Win a copy of Spring Boot in Practice this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Exception Handling - Construct Error 404 and Error 500 Manually

 
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, the Error 404 and Error 500 are returned automatically when we use HTTP.

I am working on an application that requires me construct Error 404 and Error 500 manually. My application is client application --> Core --> Wrapper --> Adaptor --> database. And I am working on the Wrapper module.

When the Wrapper contacts the Adaptor to request for some data, if resource-not-found encountered, I am supposed to put 404 status code in the HTTP header and return it to the "core". All other exception internal to the Wrapper, I am supposed to put 500 status code in the HTTP header.

Would you guide me as to how to construct the code please?

For example, I think that I can do something like: ex.getCause(); But, how do I know it is resource-not-found so that I can construct the header and put 404 there? Thank you very much.

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not sure why you want to write code for 404
you can get 404 for any server ... www.coderenach.com/abcxyz

for 500 ... in serlvet post method you can do some runtime error in java code ...

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic