How to force JsonResponse/prevent redirect? #636
Unanswered
jeremyswright
asked this question in
Q&A
Replies: 1 comment
-
Data will only throw an ValidationException which the framework will handle, implementing a thing like |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Apologies, but I've only just picked up this library so I've probably just missed something. Hoping someone can point me in the right direction.
Previously when using FormRequests to validate requests coming into API routes, I've provided a Rules function, then provided a failedValidation routine to generate a HttpResponseException, which if the request content type is JSON, returns a JsonResponse.
So I created a Data class as follows
When I submit a request with both parameters, it works fine. When I submit with one of the parameters missing I see a 302 to the homepage. I'd expect that to instead return a 422 with appropriate message. How do I force the errors to be reported as a JsonResponse?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions