ML-21: Classify API errors as transient vs permanent
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
defmodule WikipediaTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Wikipedia.API.ErrorResponse
|
||||
|
||||
describe "get_artist_summary/1" do
|
||||
test "resolves wikidata ID to Wikipedia summary with full intro" do
|
||||
wikidata_id = "Q352766"
|
||||
@@ -38,5 +40,40 @@ defmodule WikipediaTest do
|
||||
|
||||
assert {:error, :no_english_wikipedia} = Wikipedia.get_artist_summary(wikidata_id)
|
||||
end
|
||||
|
||||
@tag :capture_log
|
||||
test "promotes HTTP 200 Action API error envelopes into ErrorResponse structs" do
|
||||
wikidata_id = "Q352766"
|
||||
|
||||
Req.Test.stub(Wikipedia.API, fn conn ->
|
||||
Req.Test.json(conn, %{
|
||||
"error" => %{"code" => "ratelimited", "info" => "You've exceeded your rate limit."}
|
||||
})
|
||||
end)
|
||||
|
||||
assert {:error, %ErrorResponse{} = err} =
|
||||
Wikipedia.get_artist_summary(wikidata_id)
|
||||
|
||||
assert err.status == 200
|
||||
assert err.code == "ratelimited"
|
||||
assert err.kind == :rate_limit
|
||||
assert ErrorResponse.retryable?(err)
|
||||
end
|
||||
|
||||
@tag :capture_log
|
||||
test "classifies non-retryable Action API error codes as client errors" do
|
||||
wikidata_id = "Q352766"
|
||||
|
||||
Req.Test.stub(Wikipedia.API, fn conn ->
|
||||
Req.Test.json(conn, %{
|
||||
"error" => %{"code" => "badtoken", "info" => "Invalid CSRF token."}
|
||||
})
|
||||
end)
|
||||
|
||||
assert {:error, %ErrorResponse{kind: :client_error} = err} =
|
||||
Wikipedia.get_artist_summary(wikidata_id)
|
||||
|
||||
refute ErrorResponse.retryable?(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user