Return Exception as JSON

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Return Exception as JSON

mbn18
Hi,

One of my Controllers return JSON and I wish to configure this controller to also return the Exceptions as JSON. Is that possible?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Return Exception as JSON

Wil Moore III
This post has NOT been accepted by the mailing list yet.
One of my Controllers return JSON and I wish to configure this controller to also return the Exceptions as JSON. Is that possible?


In your ErrorController (kills me to advise you this way, but this is what the framework provides so just use it), check for an "Accept" header and respond with the appropriate "content-type" header. 
 

W: wilmoore.com

M: 303.506.8748


In matters of style, swim with the current; in matters of principle, stand like a rock. -Thomas Jefferson

--
Wil Moore III

Best Practices for Working with Open-Source Developers
http://www.faqs.org/docs/artu/ch19s02.html

Why is Bottom-posting better than Top-posting:
http://www.caliburn.nl/topposting.html

DO NOT TOP-POST and DO trim your replies:
http://linux.sgms-centre.com/misc/netiquette.php#toppost
Reply | Threaded
Open this post in threaded view
|

Re: Return Exception as JSON

outeredge
This post has NOT been accepted by the mailing list yet.
Wil Moore III wrote
In your ErrorController (kills me to advise you this way, but this is what
the framework provides so just use it), check for an "Accept" header and
respond with the appropriate "content-type" header.
I'd like to know best practice here too for ZF2, I imagine the JsonRenderer should be responsible for this but considerations would need to be made about the level of Exception detail (i.e. stack trace) that is ultimately shown in the JSON.
Reply | Threaded
Open this post in threaded view
|

Re: Return Exception as JSON

Wil Moore III
This post has NOT been accepted by the mailing list yet.
I'd like to know best practice here too for ZF2, I imagine the JsonRenderer should be responsible for this but considerations would need to be made about the level of Exception detail (i.e. stack trace) that is ultimately shown in the JSON.

--
Wil Moore III

Best Practices for Working with Open-Source Developers
http://www.faqs.org/docs/artu/ch19s02.html

Why is Bottom-posting better than Top-posting:
http://www.caliburn.nl/topposting.html

DO NOT TOP-POST and DO trim your replies:
http://linux.sgms-centre.com/misc/netiquette.php#toppost