-module(claude@types@error). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/claude/types/error.gleam"). -export([from_status/2]). -export_type([api_error/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -type api_error() :: {authentication_error, binary()} | {rate_limit_error, binary(), gleam@option:option(integer())} | {bad_request_error, binary()} | {not_found_error, binary()} | {server_error, binary(), integer()} | {connection_error, binary()} | timeout_error | {unknown_error, binary(), integer()}. -file("src/claude/types/error.gleam", 21). ?DOC( " Map an HTTP status code and response body to an ApiError.\n" "\n" " TODO: Parse the `Retry-After` header for 429 responses. Currently this\n" " always sets `retry_after: None` because only the response body is available\n" " here — plumbing the response headers through would require changes to the\n" " HTTP handling layer.\n" ). -spec from_status(integer(), binary()) -> api_error(). from_status(Status, Body) -> case Status of 401 -> {authentication_error, Body}; 403 -> {authentication_error, Body}; 429 -> {rate_limit_error, Body, none}; 400 -> {bad_request_error, Body}; 404 -> {not_found_error, Body}; S when S >= 500 -> {server_error, Body, S}; S@1 -> {unknown_error, Body, S@1} end.