java - Throwing exceptions from Spring REST webservice as JSON/XML -


i have rest web service controller looks this:

@requestmapping(value = uriconstants.url_document_search, method = requestmethod.post, produces = { mediatype.application_xml_value, mediatype.application_json_value }) protected documentsearchresponse getdocuments(@valid @modelattribute   documentsearchrequest objdmsrequest,bindingresult bindingresult, httpservletrequest objservletrequest) throws appexception {     if (bindingresult.haserrors())      {        //i want throw custom exception here   ///or can suggest more clean , efficient way      } -----more code , logic } 

i have custom exception , handlers throw invalid http invalid request exception. custom exception has errorcode , error description fields. requirement is there way parse error bindingresults custome exception , trow in controler.

what can do:

return new responseentity<string>(errordescription,httpstatus.bad_request); 

or, can hardcore if want use exception(not recommended):

try {    throw new customexception(); } catch(customexception e) {   e.printstacktrace();   return new responseentity<string>(e.geterrordescription(),e.getstatuscode()); } 

by way: returning exception it's not good, that's why don't show it.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

c# - Retrieve google contact -

javascript - How to insert selected radio button value into table cell -