Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix internal server by tightening API spec #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix internal server by tightening API spec #10

wants to merge 1 commit into from

Conversation

fornwall
Copy link

@fornwall fornwall commented May 8, 2020

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"}

These issues were found while trying out https://meeshkan.com/ on this repository.

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"}
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.

None yet

1 participant