ML-21: Classify API errors as transient vs permanent

This commit is contained in:
Claudio Ortolina
2026-04-24 13:55:00 +01:00
parent be4f4686f8
commit a1c665b490
43 changed files with 1429 additions and 135 deletions
+23
View File
@@ -0,0 +1,23 @@
defmodule MusicLibrary.ErrorResponse do
@moduledoc """
Behaviour shared by all per-API `ErrorResponse` modules.
Each API (MusicBrainz, Discogs, Wikipedia, Brave Search, OpenAI, Last.fm)
returns a struct implementing this behaviour on HTTP failure, so
`MusicLibrary.Worker.ErrorHandler.to_oban_result/1` can dispatch uniformly
to produce the right Oban tuple (`{:snooze, n}` / `{:cancel, reason}`)
without needing to know which API raised the error.
"""
@doc """
Returns `true` if the error is transient and the worker should retry after
a delay; `false` if the error is permanent and the worker should cancel.
"""
@callback retryable?(struct()) :: boolean()
@doc """
Returns the snooze delay in seconds for retryable errors. Implementations
may return any positive integer; common defaults are 3060 s.
"""
@callback retry_delay_seconds(struct()) :: pos_integer()
end