Fix internal server by tightening API spec#10
Open
fornwall wants to merge 1 commit intoOpenAPITools:masterfrom
meeshkan:fix-internal-server-errors
Open
Fix internal server by tightening API spec#10fornwall wants to merge 1 commit intoOpenAPITools:masterfrom meeshkan:fix-internal-server-errors
fornwall wants to merge 1 commit intoOpenAPITools:masterfrom
meeshkan:fix-internal-server-errors
Conversation
By specifying more constraints in the openapi.yaml file we can avoid
possible exceptions and internal server errors and instead get
descriptive validation messages on bad input.
The
curl -D- -X POST -H "Content-Type: application/json" --data "{}" http://localhost:8080/v3/store/order
request previously returned:
HTTP/1.1 500
<Map><timestamp>2020-05-08T08:00:36.259Z</timestamp><status>500</status><error>Internal Server Error</error><message>entity ID cannot be null</message><path>/v3/store/order</path></Map>
After this change it returns:
HTTP/1.1 400
<Map><timestamp>2020-05-08T08:03:46.408Z</timestamp><status>400</status><error>Bad Request</error><errors><codes><codes>NotNull.order.id</codes><codes>NotNull.id</codes><codes>NotNull.java.lang.Long</codes><codes>NotNull</codes></codes><arguments><arguments><codes><codes>order.id</codes><codes>id</codes></codes><defaultMessage>id</defaultMessage><code>id</code></arguments></arguments><defaultMessage>must not be null</defaultMessage><objectName>order</objectName><field>id</field><rejectedValue/><bindingFailure>false</bindingFailure><code>NotNull</code></errors><message>Validation failed for object='order'. Error count: 1</message><path>/v3/store/order</path></Map>
The
curl -D- -X DELETE http://localhost:8080/v3/store/order/-
request previously returned:
HTTP/1.1 500
{"timestamp":"2020-05-08T08:01:49.014Z","status":500,"error":"Internal Server Error","message":"For input string: \"-\"","path":"/v3/store/order/-"}
After this change it returns:
HTTP/1.1 400
{"timestamp":"2020-05-08T08:04:16.419Z","status":400,"error":"Bad Request","message":"Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: \"-\"","path":"/v3/store/order/-"}
The
curl -D- -X POST -H "Content-Type: application/json" --data "{}" http://localhost:8080/v3/user
request previously returned:
HTTP/1.1 500
{"timestamp":"2020-05-08T08:02:27.174Z","status":500,"error":"Internal Server Error","message":"entity ID cannot be null","path":"/v3/user"}
After this change it returns:
HTTP/1.1 400
{"timestamp":"2020-05-08T08:04:38.026Z","status":400,"error":"Bad Request","errors":[{"codes":["NotNull.user.id","NotNull.id","NotNull.java.lang.Long","NotNull"],"arguments":[{"codes":["user.id","id"],"arguments":null,"defaultMessage":"id","code":"id"}],"defaultMessage":"must not be null","objectName":"user","field":"id","rejectedValue":null,"bindingFailure":false,"code":"NotNull"},{"codes":["NotNull.user.username","NotNull.username","NotNull.java.lang.String","NotNull"],"arguments":[{"codes":["user.username","username"],"arguments":null,"defaultMessage":"username","code":"username"}],"defaultMessage":"must not be null","objectName":"user","field":"username","rejectedValue":null,"bindingFailure":false,"code":"NotNull"}],"message":"Validation failed for object='user'. Error count: 2","path":"/v3/user"}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By specifying more constraints in the openapi.yaml file we can avoid possible exceptions and internal server errors and instead get descriptive validation messages on bad input.
The
request previously returned:
After this change it returns:
The
request previously returned:
After this change it returns:
The
request previously returned:
After this change it returns:
These issues were found while trying out https://meeshkan.com/ on this repository.