-
Notifications
You must be signed in to change notification settings - Fork 77
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
Format required checks for relationships #299
Format required checks for relationships #299
Conversation
Ensures, when relationships are specified, that the root is an object and reach relationships contains a data member with a well-formed resource linkage per: * https://jsonapi.org/format/#crud-creating * https://jsonapi.org/format/#crud-updating-resource-relationships * https://jsonapi.org/format/#document-resource-object-relationships * https://jsonapi.org/format/#document-resource-object-linkage
@spec send_error(Plug.Conn.t(), term()) :: term() | ||
def send_error(conn, %{errors: [%{status: status}]} = error), | ||
do: send_error(conn, status, error) | ||
|
||
def send_error(conn, %{errors: errors} = error) when is_list(errors) do | ||
status = Enum.max_by(errors, &Map.get(&1, :status)) |
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.
Best I can tell this was not called on the latest stable version prior to this PR. I think this is a safe change as long as it works in the new workflows.
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.
This is a great improvement to error handling. Excited to merge once we've settled the last couple of things!
Uses a new `error_attrs` type to represent the raw output of `build_error`. This is the output of some of the newer error functions. Also includes an `error_attrs` suffix on those functions to highlight that they return the raw `build_error` output structure instead of the JSON:API-friendly error structure returned by most of the other ErrorView functions.
Best I can tell some sort of build cache error caused linting to fail. Seems to lint fine for me locally. |
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.
Thanks! Big improvement to error handling in the given malformed relationship cases.
This PR updates the JSON:API format verification plug to include checks for the relationships key when creating and updating resources.
This is intended to address: #294
Additionally this PR:
ErrorView.send_error/2
because I don't think it extracted the status code previously