oscarotero / psr7-middlewares

[DEPRECATED] Collection of PSR-7 middlewares
MIT License
668 stars 56 forks source link

allow JSON-validator default error-handler to be overridden. #58

Closed abacaphiliac closed 7 years ago

abacaphiliac commented 7 years ago

based on some feedback here: https://github.com/oscarotero/psr7-middlewares/pull/46

the error handler receives the psr request, response, and an array of validation errors. the default error handler responds with a 422 status code, application/json content-type, and the json-encoded array of errors.

the route-based multi-file wrapper also accepts an error handler override, which is passed through to the underlying validator.

@oscarotero @sbol-coolblue please tell me what you think.

oscarotero commented 7 years ago

Hello. Thanks for you work. I suggest the following:

You can see, for example in the errorHandler middleware:

abacaphiliac commented 7 years ago

@oscarotero thank you. will make updates ASAP.

abacaphiliac commented 7 years ago

@oscarotero implemented suggestions.

are you ok with the public constant KEY for the attribute key? i named it for consistency. is there a value i should use instead of "JSON_ERRORS"?

oscarotero commented 7 years ago

@abacaphiliac JSON_ERRORS is fine but maybe I'd use a more specific key (such JSON_VALIDATION_ERRORS) to say clearly that are validation errors, not parsing errors (or other type of errors). Anyway, I think it's a great work. Thank you.

abacaphiliac commented 7 years ago

@oscarotero thank you for the guidance. i'll update to the more specific key value, add some error handler docs per suggestion by @sbol-coolblue , and squash the commits.

abacaphiliac commented 7 years ago

@oscarotero squashed. please let me know if there is something else i can do.

oscarotero commented 7 years ago

@abacaphiliac Just one thing and I'll merge (I swear): A way to get the errors in the same way than, for example ErrorHandler

So, the error handler could be something like this:

$errors = JsonValidator::getErrors($request);

echo json_encode($errors, JSON_UNESCAPED_SLASHES);

Thanks

abacaphiliac commented 7 years ago

@oscarotero no worries. we're in this together, however long it takes : )

the static helper simplified my unit tests. thanks for the suggestion. i do have another recommendation now. i'll submit another request.

abacaphiliac commented 7 years ago

implemented the suggestion, btw.

abacaphiliac commented 7 years ago

@oscarotero checking in. any outstanding TODOs that i'm missing?

oscarotero commented 7 years ago

Sorry, I did not received the notification. Merged. Thanks for your effort (and patience) 👍

abacaphiliac commented 7 years ago

@oscarotero my pleasure. i hope we get the chance to collaborate again : )