-
Notifications
You must be signed in to change notification settings - Fork 138
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
Request errors #126
Request errors #126
Conversation
76112f6
to
39818e9
Compare
@richmolj Would like to get your feedback on the approach before I drive across the finish line. The current implementation would replace the typecasting & writability checks currently in |
Instead of having the message change dramatically depending on whether an AttributeError is a missing attribute or an access error, we subclass and create a message based on the subclass.
This is the first phase of work to allow us to provide better & more actionable errors to API users who might not also be developers of the API itself. Previously when trying to write unwritable attributes & relationships, on typecast problems, or trying to write an attribute that doesn't exist, the request would blow up with a 500 and an unhelpful error message. The request validator takes on most of the work of transforming and validating an incoming request for processing all while rescuing any of the above errors and turning them into helpful error messages. Note that this is only currently intended to process write payloads, but will be fully extendable to validate query parameters for read requests too. This doesn't actually integrate the validator into the code path, as I want to get feedback on the design before doing that work in case anything needs to change. This will take over some of the normalization responsibilities which currently live in `Graphiti::Util::Persistence`. This also adds a new "payload_path" key to the meta payload for the deserialized/normalized request payload, which allows consumers to know which path within the request json structure they are dealing with at any given time. Here it is used for more useful error messages.
39818e9
to
43caaca
Compare
43caaca
to
6ad47e6
Compare
@richmolj This should be good to go. Going to follow up with changes to graphiti_errors later this weekend/early next week so that we can render nice errors back to API consumers. |
6ad47e6
to
6da3770
Compare
The `Graphiti::Base` module was a legacy from jsonapi_suite that was mixed into the `Graphiti::Runner` and `Graphiti` modules to provide them both with functionality. Turns out we weren't using the latter case anymore so there's no reason for this to remain a separate concern.
6da3770
to
bc1d903
Compare
Calling `.find()`, `.build()`, or `.all()` on a resource will now run validations on the incoming params hash and raise an error if the payload is incorrect. It will also be easy to integrate url request params for read requests, as we will just need to add the error handling to the validator and they will correctly propogate.
bc1d903
to
892a0f6
Compare
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.
Looks really solid. A few tiny questions just to double-check my understanding but great PR. Let's also run through the ED sample app to sanity check before merge.
@@ -180,12 +164,8 @@ def process_has_many(relationships, caller_model) | |||
iterate(except: [:polymorphic_belongs_to, :belongs_to]) do |x| | |||
yield x | |||
|
|||
if x[:sideload].writable? |
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.
because this check happens upstream in the validator 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.
As far as I can tell this can't happen in a way that doesn't go through the runner which does the validator check. Let me know if this isn't true for any reason you're aware of.
7f9d307
to
e789708
Compare
Pushed updates. Let's get graphiti_errors#5 merged and released before this is merged in. |
This is the first phase of work to allow us to provide better & more
actionable errors to API users who might not also be developers of the
API itself. Previously when trying to write unwritable attributes &
relationships, on typecast problems, or trying to write an attribute
that doesn't exist, the request would blow up with a 500 and an
unhelpful error message. The request validator takes on most of the
work of transforming and validating an incoming request for processing
all while rescuing any of the above errors and turning them into helpful
error messages. Note that this is only currently intended to process
write payloads, but will be fully extendable to validate query
parameters for read requests too.
This also adds a new "payload_path" key to the meta payload for the
deserialized/normalized request payload, which allows consumers to know
which path within the request json structure they are dealing with at
any given time. Here it is used for more useful error messages.