You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: opt-in HTTP error taxonomy with overridable mapping (#216)
Adds an opt-in (config.raise_error_taxonomy, default false) typed NxtHttpClient::Error taxonomy for HTTP status + network/code-0 failures, a map_error DSL to override the mapping per client, a json_response empty/204-body guard, credential redaction in Error#to_h, and Sentry reporting via set_context. Backwards compatible (taxonomy off by default). HELDENPMI-132.
Copy file name to clipboardExpand all lines: README.md
+81-6Lines changed: 81 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ class UserServiceClient < NxtHttpClient::Client
48
48
# Note: This error handler is set by default when you use
49
49
# config.raise_response_errors = true
50
50
handler.on(:error) do|response|
51
-
Sentry.set_extras(http_error_details: error.to_h)
51
+
Sentry.set_context('http_error', error.to_h)
52
52
raise StandardError, "I can't handle this: #{response.code}"
53
53
end
54
54
end
@@ -118,12 +118,16 @@ Register your default request options on the class level. Available options are:
118
118
- `base_url=`
119
119
- `x_request_id_proc=`
120
120
- `json_request=`: Shorthand to set the Content-Type request header to JSON and automatically convert request bodies to JSON
121
-
- `json_response=`: Shorthand to set the Accept request header and automatically convert success response bodies to JSON
122
-
- `raise_response_errors=`: Makes the client raise a `NxtHttpClient::Error`for a non-success response.
123
-
You can also do this manually by setting a response_handler.
121
+
- `json_response=`: Shorthand to set the Accept request header and automatically convert success response bodies to JSON (an empty/204 body becomes `nil`)
122
+
- `raise_response_errors=`: Makes the client raise a generic `NxtHttpClient::Error`for a non-success response.
123
+
Superseded by `raise_error_taxonomy` (which raises typed errors and takes precedence when both are set); kept for
124
+
backward compatibility.
125
+
- `raise_error_taxonomy=`: Defaults to `false`. Opt in to raise the mapped `NxtHttpClient::Error` taxonomy
126
+
(`ClientError`/`ServerError`/`NetworkError` subclasses) on an unhandled 4xx/5xx/code-0 response instead of
127
+
returning it. See [Error taxonomy](#error-taxonomy).
124
128
- `bearer_auth=`: Set a bearer token to be sent in the Authorization header
125
129
- `basic_auth=`: Pass a Hash containing `:username` and `:password`, to be sent as Basic credentials in the Authorization header
0 commit comments