Open kristenmills opened 9 years ago
This is useful in the HTML form POST use case not the API server request.
Kristen is correct.
If you read the README, you'll note that I added a comment on this. This behavior occurs only from a browser context. From an AJAX/XmlHtttpRequest context, errors are simply dumped out in a JSON object.
Seeing as we NEVER want the browser context case can't we just disable this behavior altogether?
So what would happen if we had a <form method="POST" action="/api/v1/members">
with invalid data? Just dump the user at a screen with JSON output?
There's really no reason to spend time or effort on disabling a "feature" (I'd argue it's basic functionality) that we will never even touch. Let's focus our efforts elsewhere.
$.02 deposited.
@craigcabrey at least it's less mystifying than silently erroring and would indicate that we need to do something about it. Seeing as we're not hosting the front-end on the api server the redirect is actually misbehaving. If we want to redirect with errors in the GET request I'm okay with that but we shouldn't leave it the way it is because it promotes improper usage.
Looks like the solution is to override the response function in your FormRequest subclass: https://github.com/laravel/framework/blob/master/src/Illuminate/Foundation/Http/FormRequest.php
Quote from
This is not the behavior we want. And I spent 3 hours thinking I had seriously broke something when I kept getting a token back on random POST requests when the issue was that my JSON body was just invalid.