- 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 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 Constructor Description HttpErrorException(int statusCode)Creates a HTTP error with status code only.HttpErrorException(int statusCode, String message)Creates a HTTP error with status code and error message.HttpErrorException(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()booleanisClientErrorCode()booleanisInformationalCode()booleanisRedirectCode()booleanisServerErrorCode()booleanisSuccessCode()-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Constructor Detail
-
HttpErrorException
public 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
public 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
public 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()
-
isInformationalCode
public final boolean isInformationalCode()
-
isSuccessCode
public final boolean isSuccessCode()
-
isRedirectCode
public final boolean isRedirectCode()
-
isClientErrorCode
public final boolean isClientErrorCode()
-
isServerErrorCode
public final boolean isServerErrorCode()
-
-