fix: silence 404s when watch order not found
This commit is contained in:
@@ -54,6 +54,9 @@ func (c *Client) getWatchOrder(ctx context.Context, id int) (watchorder.WatchOrd
|
|||||||
result, err := watchorder.FetchWatchOrder(requestCtx, c.httpClient, watchOrderURL)
|
result, err := watchorder.FetchWatchOrder(requestCtx, c.httpClient, watchOrderURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var statusError *watchorder.HTTPStatusError
|
var statusError *watchorder.HTTPStatusError
|
||||||
|
if errors.As(err, &statusError) && statusError.StatusCode == 404 {
|
||||||
|
return watchorder.WatchOrderResult{}, watchorder.ErrWatchOrderNotFound
|
||||||
|
}
|
||||||
if errors.Is(err, watchorder.ErrWatchOrderMarkupNotFound) {
|
if errors.Is(err, watchorder.ErrWatchOrderMarkupNotFound) {
|
||||||
log.Printf("relations: watch-order markup missing for %d (%s): %v", id, watchOrderURL, err)
|
log.Printf("relations: watch-order markup missing for %d (%s): %v", id, watchOrderURL, err)
|
||||||
} else if errors.As(err, &statusError) {
|
} else if errors.As(err, &statusError) {
|
||||||
@@ -95,6 +98,9 @@ func (c *Client) currentOnlyRelation(ctx context.Context, id int) ([]RelationEnt
|
|||||||
func (c *Client) GetFullRelations(ctx context.Context, id int) ([]RelationEntry, error) {
|
func (c *Client) GetFullRelations(ctx context.Context, id int) ([]RelationEntry, error) {
|
||||||
result, err := c.getWatchOrder(ctx, id)
|
result, err := c.getWatchOrder(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, watchorder.ErrWatchOrderNotFound) {
|
||||||
|
return c.currentOnlyRelation(ctx, id)
|
||||||
|
}
|
||||||
log.Printf("relations: using current-only fallback for %d: %v", id, err)
|
log.Printf("relations: using current-only fallback for %d: %v", id, err)
|
||||||
return c.currentOnlyRelation(ctx, id)
|
return c.currentOnlyRelation(ctx, id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ var malLinkPattern = regexp.MustCompile(`myanimelist\.net/anime/(\d+)`)
|
|||||||
|
|
||||||
var ErrInvalidWatchOrderURL = errors.New("invalid watch order url")
|
var ErrInvalidWatchOrderURL = errors.New("invalid watch order url")
|
||||||
var ErrWatchOrderMarkupNotFound = errors.New("watch order markup not found")
|
var ErrWatchOrderMarkupNotFound = errors.New("watch order markup not found")
|
||||||
|
var ErrWatchOrderNotFound = errors.New("watch order not found")
|
||||||
|
|
||||||
type HTTPStatusError struct {
|
type HTTPStatusError struct {
|
||||||
StatusCode int
|
StatusCode int
|
||||||
|
|||||||
Reference in New Issue
Block a user