Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8350885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:27:33+00:00 2026-06-09T08:27:33+00:00

I have Restful API that responds 404 errors when an item is not found,

  • 0

I have Restful API that responds 404 errors when an item is not found, but have different messages depending on the reason why the item is not found (unknown, not available, …), it is done this way using Spring MVC :

response.sendError(HttpServletResponse.SC_NOT_FOUND, "NOT_AVAILABLE");

(this works fine with any browser, displaying 404 errors with “NOT_AVAILABLE” as message)

Now, I’d like to get that message back into my Java code using Spring RestTemplate in order to manage them.
I tried this:

try {
    rest.put(apiRootUrl + "/item/{itemId}", null, itemId);
} catch (HttpClientErrorException e) {
    if (NOT_FOUND == e.getStatusCode()) {
        switch (MyErrorCode.valueOf(e.getStatusText())) {
            case NOT_AVAILABLE:
                return displayNotAvailableError();
            case UNKNOWN:
                return displayUnknownError();
            default:
                // ...
        }
    }
}

but in the getStatusText(), I always got the NOT FOUND label (from 404) and not my custom value.

Does someone know if it is possible to retrieve the custom message from 404 errors? And therefore how?

thanks a lot!

Edit: I run on a Tomcat server (which sends the 404 HTML page) and this does not append with a Weblogic server

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:27:36+00:00Added an answer on June 9, 2026 at 8:27 am

    OK, after digging a bit more, the solution is in fact very simple !

    Tomcat was sending back to me its default 404 page, I just needed to tell it to use mine!

    How to do this:

    • create a 404.jsp page like this:

      <%@ page pageEncoding="UTF-8" %>
      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
      <c:out value="${requestScope['javax.servlet.error.message']}"/>
      
    • reference it in your web.xml

      <error-page>
          <error-code>404</error-code>
          <location>/error/404.jsp</location>
      </error-page>
      

    And now, you can get the message in your client using e.getStatusText()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom implementation of a RESTful API for a PHP application that
I'm creating a RESTful API that returns JSON or XML depending on the Accept
We have a RESTful API that we are doing in MVC3. We would like
I want to add user authentication to my restful api that I have created
So we have some internal applications that provide metrics via a RESTful api. We
I am trying out a RESTful API that has OAuth. I have the API
I have a service with a Django-based RESTful API that is designed for iOS
In an ideal RESTful API that supports multiple accounts, should each resource have it's
I have a RESTful API created with ASP.NET MVC2 that returns all data as
I have a web service that returns some XML data using a RESTful API.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.