http-api-problem icon indicating copy to clipboard operation
http-api-problem copied to clipboard

Idea: Convert from hyper::Error to ApiError

Open Tokarak opened this issue 10 months ago • 0 comments

See hyper::Error documentation. It provides many is_xyz methods which seem to describe some private enum.

The question is: is there enough information to canonically convert a hyper::Error into an ApiError? (alternatively, ApiErrorBuilder; also, directly into a HttpApiProblem) This is important, because it's important to know whether to canonically give a '4xx' or '5xx' error: server-side or client-side?


Consider my use case: https://github.com/redlib-org/redlib, which is effectively a proxy-client for Reddit. I'm trying to refactor the error handling to use this library. Often, a hyper request body or response body needs to be aggregated, which is fallible: e.g connection timed out, DNS error, malicious/malformed content from the user; all of these generate a hyper error.

Between a client and Redlib (These are statuses that a user will likely see):

  • is_timeout -> 408
  • is_parse -> 400
  • is_parse_too_large -> 413 There are a lot of other possible flags that I don't understand fully.

Now, between Redlib and the external web, i.e Reddit:

  • is_timout -> 504
  • is_Connect -> 504
  • everything else -> mostly 502, some 500

Thoughts? Is there a better pattern than this?

Tokarak avatar Mar 18 '25 23:03 Tokarak