Repository navigation
fix: findOrFail with no row answers 404, not 500 - #41
Merged
Merged
Conversation
ModelNotFoundException was a plain Exception. So Dox answered 500 and logged it as a server error when findOrFail() or firstOrFail() found no row. Now it extends IHttpException with code 404. The body is the normal Dox 404 body. The table, column and id are not sent.
Contributor
Author
Bot reviewVerdict: OK to merge. Nothing blocking. What I checked
Non-blocking
|
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.
Problem
findOrFail()andfirstOrFail()throwModelNotFoundExceptionwhen no row matches. It was a plainException. So in a Dox app the answer was 500, and Dox logged it as a server error. Laravel answers 404 here.Fix
ModelNotFoundExceptionnow extendsIHttpExceptionwith code 404.IHttpExceptionis in dox_annotation, which dox_orm already uses. No new dependency.The answer is the normal Dox 404 body:
{"code": "not_found", "message": "Not Found"}The table, column and id are not sent to the client. Dox does not log 4xx HTTP exceptions, so it is no longer logged as a server error.
Not breaking
on ModelNotFoundException catchstill works.table,idandcolumnfields, and the sametoString().Exception.const.IHttpExceptionhas fields that can change, so a const constructor is not possible. Only code that wroteconst ModelNotFoundException(...)must dropconst.Tests
IHttpExceptionwith code 404, keeps its fields, and its body has no table or id.findOrFailand no row gives 404 with the body above.DRIVER=sqlite dart test: 560 passed, 2 skipped.