This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
Conversation
This file contains 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
This code will never throw an InvalidParameterException, so document that it does.
Because getOffset throws an exception, the assertEquals was never even being run. Removing it makes things clearer that only an exception is expected.
There were no tests for the code paths in getInclude and getSort that would throw an InvalidParameterException. These tests hit that code path to improve code coverage.
By giving these unique exceptions a unique code, it's possible they can be caught and handled separately.
The exception codes can be useful for referencing the specific error that was thrown.
nubs
force-pushed
the
enhance-invalid-parameter-exceptions
branch
from
April 28, 2016 15:39
ec7da65
to
463ac85
Compare
@@ -12,7 +12,32 @@ | |||
namespace Tobscure\JsonApi\Exception; | |||
|
|||
use Exception; | |||
use Throwable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's PHP 7 only, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, strange that the tests passed on older PHP versions - I'll remove the typehints though.
By including the JSON API source with InvalidParameterException's, the caller is better informed on what action to take to fix their request. The [JSON API docs](http://jsonapi.org/format/#error-objects) go into some detail on how to specify the source of the error.
nubs
force-pushed
the
enhance-invalid-parameter-exceptions
branch
from
April 29, 2016 01:34
463ac85
to
f98653e
Compare
Great work, thanks! Sorry it took so long to get it in :/ |
No worries. Thanks for taking a look! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This fixes a couple minor issues in documentation/tests, adds some additional tests related to
InvalidParameterException
s, and most importantly adds some new functionality to these exceptions.A unique exception code is added to each of the thrown
InvalidParameterException
s in theParameters
class. This code is returned in the JSON APIerrors
response built by theInvalidParameterExceptionHandler
.Also, the "source" of the error is exposed when available by setting which parameter was invalid on the exception.
An example JSON API error response from the included exception handler before this change:
{ "errors": [ {} ] }
An example JSON API error response after this change:
Thanks for this library! It's been a joy to work with.