API client call result shape?

Working on an API client and wondering what would be a proper result shape for error
have it as

{:error, %{error: error_returned_by_endpoint, headers: list_of_headers, status: status_code}}

Client has local validation though so if payload fails local validation what would be a proper result shape:

{:error, %{error: validation_errors}}

or something like:

{:error, %{error: validation_errors, headers:[], status: nil}
1 Like

I would probably go for something like:

{:error, {:application, %{error: endpoint_error, headers: headers, status: status}}}
{:error, {:network, ...}} # in case request fails completely
{:error, {:validation, ...}}

You could even consider getting rid of the outer tuple and :error atom. This allows you to easily pattern match and distinguish cases that might be treated differently - do I need to retry the request or not, etc.

1 Like

Thank you that looks much nicer