这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@danielgtaylor
Copy link
Owner

This PR changes the status code behavior for errors to attempt to return more specific status codes when possible while still striving for exhaustive error responses. As can be seen in the README, the new flow is:

flowchart TD
	Request[Request has errors?] -->|yes| Panic
	Request -->|no| Continue[Continue to handler]
	Panic[Panic?] -->|yes| 500
	Panic -->|no| RequestBody[Request body too large?]
	RequestBody -->|yes| 413
	RequestBody -->|no| RequestTimeout[Request took too long to read?]
	RequestTimeout -->|yes| 408
	RequestTimeout -->|no| ParseFailure[Cannot parse input?]
	ParseFailure -->|yes| 400
	ParseFailure -->|no| ValidationFailure[Validation failed?]
	ValidationFailure -->|yes| 422
	ValidationFailure -->|no| 400
Loading

The change is fairly small & unobtrusive. Several tests have been updated to reflect the changes. It should not break clients, however your API will have new documented responses when upgrading Huma.

Note: the above flowchart deliberately excludes stuff like 405 Method Not Allowed because that returns at the low-level router before any of the above executes.

@codecov
Copy link

codecov bot commented Apr 12, 2022

Codecov Report

Merging #41 (257ac75) into main (6f5d76f) will increase coverage by 0.37%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #41      +/-   ##
==========================================
+ Coverage   86.23%   86.61%   +0.37%     
==========================================
  Files          24       24              
  Lines        1911     1927      +16     
==========================================
+ Hits         1648     1669      +21     
+ Misses        186      183       -3     
+ Partials       77       75       -2     
Impacted Files Coverage Δ
context.go 87.80% <ø> (ø)
operation.go 82.48% <100.00%> (+3.41%) ⬆️
resolver.go 86.05% <100.00%> (+1.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f5d76f...257ac75. Read the comment docs.

@danielgtaylor danielgtaylor merged commit f67bd7b into main Apr 13, 2022
@danielgtaylor danielgtaylor deleted the error-status branch April 13, 2022 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants