- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- io.rxmicro.common.RxMicroException
-
- io.rxmicro.http.error.HttpErrorException
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
InternalHttpErrorException,RedirectException,ValidationException
public abstract class HttpErrorException extends io.rxmicro.common.RxMicroExceptionBase exception for all not success HTTP response statuses.Each reactive type of returned request handler result supports two states:
- Successful completion signal.
- Completion signal with an error.
The feature of a successful completion signal consists in its uniqueness, i.e. if such a signal has occurred, it ensures successful completion of the business task. The feature of a completion signal with an error is that different types of errors may occur during the execution of the business task:
- validation error;
- data source connection error;
- computational algorithm error, etc.
It means that each request handler can return only one successful result and several results with errors.
So the RxMicro framework introduces the error concept. An error means any unsuccessful result. For simplified error handling, the RxMicro framework recommends using HTTP status codes for each error category! In case the HTTP code status is not sufficient, the RxMicro framework recommends using an additional text description.
For this purpose, the RxMicro framework defines a standard JSON model which is returned in case of any error:
{ "message": "Not Found" }Thus, in case of an error, the client determines the error category basing on HTTP status code analysis. For more information, the client should analyze a text message.
For all child classes which extend the HttpErrorException class, when creating an exception instance the stack trace is not filled, as this information is redundant. (This behavior is achieved by using the
RuntimeException(String, Throwable, boolean, boolean).)- Since:
- 0.1
- Author:
- nedis
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedHttpErrorException(int statusCode)Creates a HTTP error with status code only.protectedHttpErrorException(int statusCode, String message)Creates a HTTP error with status code and error message.protectedHttpErrorException(int statusCode, String message, Object... args)Creates a HTTP error with status code and error message.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetStatusCode()Returns the HTTP status code for current instance of exception.booleanisClientErrorCode()Returnstrueif the current instance of exception has a client error status code.booleanisInformationalCode()Returnstrueif the current instance of exception has a informational status code.booleanisRedirectCode()Returnstrueif the current instance of exception has a redirect status code.booleanisServerErrorCode()Returnstrueif the current instance of exception has a server error status code.booleanisSuccessCode()Returnstrueif the current instance of exception has a success status code.-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Constructor Detail
-
HttpErrorException
protected HttpErrorException(int statusCode, String message)Creates a HTTP error with status code and error message.For all child classes which extend the HttpErrorException class, when creating an exception instance the stack trace is not filled, as this information is redundant.
(This behavior is achieved by using the
RuntimeException(String, Throwable, boolean, boolean).)- Parameters:
statusCode- the status codemessage- the error message- Throws:
NullPointerException- if the error message isnull
-
HttpErrorException
protected HttpErrorException(int statusCode, String message, Object... args)Creates a HTTP error with status code and error message.For all child classes which extend the HttpErrorException class, when creating an exception instance the stack trace is not filled, as this information is redundant.
(This behavior is achieved by using the
RuntimeException(String, Throwable, boolean, boolean).)(FYI: This constructor uses
Formats.format(String, Object...)method to format error message.)- Parameters:
statusCode- the status codemessage- the error message templateargs- the error message template argument- Throws:
NullPointerException- if the error message template isnullIllegalArgumentException- if detected a redundant placeholder or missing argument
-
HttpErrorException
protected HttpErrorException(int statusCode)
Creates a HTTP error with status code only.For all child classes which extend the HttpErrorException class, when creating an exception instance the stack trace is not filled, as this information is redundant.
(This behavior is achieved by using the
RuntimeException(String, Throwable, boolean, boolean).)- Parameters:
statusCode- the status code
-
-
Method Detail
-
getStatusCode
public final int getStatusCode()
Returns the HTTP status code for current instance of exception.- Returns:
- the HTTP status code for current instance of exception
-
isInformationalCode
public final boolean isInformationalCode()
Returnstrueif the current instance of exception has a informational status code.- Returns:
trueif the current instance of exception has a informational status code
-
isSuccessCode
public final boolean isSuccessCode()
Returnstrueif the current instance of exception has a success status code.- Returns:
trueif the current instance of exception has a success status code
-
isRedirectCode
public final boolean isRedirectCode()
Returnstrueif the current instance of exception has a redirect status code.- Returns:
trueif the current instance of exception has a redirect status code
-
isClientErrorCode
public final boolean isClientErrorCode()
Returnstrueif the current instance of exception has a client error status code.- Returns:
trueif the current instance of exception has a client error status code
-
isServerErrorCode
public final boolean isServerErrorCode()
Returnstrueif the current instance of exception has a server error status code.- Returns:
trueif the current instance of exception has a server error status code
-
-