Am Fr., 11. Jan. 2019 um 05:57 Uhr schrieb Mike Orr <[email protected]>:

> Is there a simple way to convert a Response to an HTTP string; i.e.,
> with headers and a body like it would send to the client?
>
> I have a JSON backend view that sends an HTTP exception like this:
>
> # HTTP 422, simulating a validation error
> jreq = {"email": "[email protected]", "errors": {"email": "Test error."}}
> raise pyramid.httpexceptions.HTTPUnprocessableEntity(json=jreq)
>
> The frontend makes an AJAX call using Backbone Model.save(), and in
> the error callback the response is status 422 as it should be, but it
> doesn't appear to contain the data. .responseJSON contains the kind of
> things that appear on an exception page, and my data object doesn't
> appear to be anywhere.
>
> ogle.com/d/optout <https://groups.google.com/d/optout>.
>
I'm not sure how preconfigured exceptions like HTTPUnprocessableEntity
handle data but
if you return a custom HTTP Response with status=422 and json data it
works.

But most JS Frameworks do not automatically parse the orginal json body if
the HTTP
status is not OK (200 ... 299). You will have to get the body and parse the
json manually in
your frontend code.
Maybe that's the issue here?

Arndt.

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/CAJYR-0PLsn7EmWGVsLmsUd1fLCwaXAX2FZ870rUL3W6TAA1mJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to