Class HttpStatusException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.io.IOException
org.biojava.nbio.core.util.HttpStatusException
All Implemented Interfaces:
Serializable

public class HttpStatusException extends IOException
Signals that an HTTP request completed but returned a status code outside the 2xx range.

This exists so that callers can tell apart the two very different reasons a download can fail:

  • The resource does not exist (isNotFound(), i.e. HTTP 404 or 410). For a caller that tries several mirrors or several alternative data sources in turn, this simply means "not here, try the next one".
  • Anything else — a server error, a redirect that was not followed, an authentication failure. These usually mean the whole operation should be abandoned rather than silently treated as "no data available".
Without a distinct exception type the only way to tell these apart is by parsing the message of a plain IOException, which is brittle.
Since:
7.3.0
Author:
Amr ALHOSSARY
See Also:
  • Constructor Details

    • HttpStatusException

      public HttpStatusException(int statusCode, String url, String responseMessage)
      Parameters:
      statusCode - the HTTP status code returned by the server
      url - the URL that was requested
      responseMessage - the HTTP reason phrase, may be null
  • Method Details

    • getStatusCode

      public int getStatusCode()
      Returns:
      the HTTP status code returned by the server
    • getUrl

      public String getUrl()
      Returns:
      the URL that was requested
    • isNotFound

      public boolean isNotFound()
      Whether the status indicates that the resource is simply not there, as opposed to a transport or server problem.
      Returns:
      true for HTTP 404 (Not Found) and 410 (Gone)