[Logo]
Forums Register Login
How to pass the translated error message to the front-end?
1. Created @ControllerAdvice and caught few exceptions. ex: FileNotFoundException or User Defined exception
2. Translated the error message - error message + parameters and constructed the proper error message.

Now not sure how to send the response to the front-end

Currently 500 error is thrown. I have kept the return type as user defined object.

Someone please advise how to gracefully throw an error message to the front-end so that it will be displayed to the user without any issues.

you can use ModelAndView object. set the error message  and return ModelAndView object as response.

Please check below code. It helps.


write this piece of code inside @ControllerAdvice annotation class.

I used the same code...However 500 error is returned and the page got redirected to the error page

I want the same page or window or dialog should be retained..

Please advise.
 

Kathir jeyap wrote:
I used the same code...However 500 error is returned and the page got redirected to the error page

I want the same page or window or dialog should be retained..

Please advise.



Why 500 is returned. Could you post the code you've written or the exception that is thrown?
I see in the javascript in ajax call we have only success case and inside the success case we have differentiated as success or error based on the response type

If we add the failure in ajax script and handle this will it be handled ??

What should be the right way in the front-end for ajax calls ???
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards


This thread has been viewed 73 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 19, 2018 13:15:17.