This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

How to pass the translated error message to the front-end?  RSS feed

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kathir jeyap
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
vipul John
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Kathir jeyap
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ???
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!