Package com.networknt.status
Class Status
- java.lang.Object
-
- com.networknt.status.Status
-
public class Status extends Object
For every status response, there is only one message returned. This means the server will fail fast and won't return multiple message at all. Two benefits for this design:1. low latency as server will return the first error without further processing 2. limited attack risks and make the error handling harder to analyzed
- Author:
- Steve Hu
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONFIG_NAMEstatic StringdefaultSeveritystatic StringSHOW_DESCRIPTIONstatic StringSHOW_MESSAGEstatic StringSHOW_METADATA
-
Constructor Summary
Constructors Constructor Description Status()Default construction that is only used in reflection.Status(int statusCode, String code, String message, String description)Construct a status object based on all the properties in the object.Status(int statusCode, String code, String message, String description, String severity)Construct a status object based on all the properties in the object.Status(HttpStatus httpStatus, String message, String description)Construct a status object based on all the properties in the object.Status(String code, Object... args)Construct a status object based on error code and a list of arguments.Status(String code, Map<String,Object> metadata, Object... args)Construct a status object based on error code and a list of arguments.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetCode()static Map<String,Object>getConfig()This static method is very important for any customized status wrapper to get the light-4j status before customizing it.StringgetDescription()StringgetMessage()Map<String,Object>getMetadata()StringgetSeverity()intgetStatusCode()voidputMetadata(String key, Object value)put key value pair to the metadatastatic voidreload()voidsetCode(String code)voidsetDescription(String description)voidsetMessage(String message)voidsetMetadata(Map<String,Object> metadata)voidsetSeverity(String severity)voidsetStatusCode(int statusCode)static booleanshouldShowDescription()static booleanshouldShowMessage()static booleanshouldShowMetadata()StringtoString()StringtoStringConditionally()This method is used to construct a Status with fields conditionally.
-
-
-
Field Detail
-
CONFIG_NAME
public static final String CONFIG_NAME
- See Also:
- Constant Field Values
-
defaultSeverity
public static final String defaultSeverity
- See Also:
- Constant Field Values
-
SHOW_METADATA
public static final String SHOW_METADATA
- See Also:
- Constant Field Values
-
SHOW_DESCRIPTION
public static final String SHOW_DESCRIPTION
- See Also:
- Constant Field Values
-
SHOW_MESSAGE
public static final String SHOW_MESSAGE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Status
public Status()
Default construction that is only used in reflection.
-
Status
public Status(String code, Object... args)
Construct a status object based on error code and a list of arguments. It is the most popular way to create status object from status.yml definition.- Parameters:
code- Error Codeargs- A list of arguments that will be populated into the error description
-
Status
public Status(String code, Map<String,Object> metadata, Object... args)
Construct a status object based on error code and a list of arguments. It is the most popular way to create status object from status.yml definition.- Parameters:
code- Error Codeargs- A list of arguments that will be populated into the error descriptionmetadata- a map of metadata attributes
-
Status
public Status(int statusCode, String code, String message, String description)Construct a status object based on all the properties in the object. It is not very often to use this construct to create object.- Parameters:
statusCode- Status Codecode- Codemessage- Messagedescription- Description
-
Status
public Status(HttpStatus httpStatus, String message, String description)
Construct a status object based on all the properties in the object. It is not very often to use this construct to create object.- Parameters:
httpStatus- HttpStatusmessage- Messagedescription- Description
-
Status
public Status(int statusCode, String code, String message, String description, String severity)Construct a status object based on all the properties in the object. It is not very often to use this construct to create object.- Parameters:
statusCode- Status Codecode- Codeseverity- Status Severitymessage- Messagedescription- Description
-
-
Method Detail
-
getStatusCode
public int getStatusCode()
-
setStatusCode
public void setStatusCode(int statusCode)
-
getCode
public String getCode()
-
setCode
public void setCode(String code)
-
getMessage
public String getMessage()
-
setMessage
public void setMessage(String message)
-
getDescription
public String getDescription()
-
setDescription
public void setDescription(String description)
-
setSeverity
public void setSeverity(String severity)
-
getSeverity
public String getSeverity()
-
shouldShowMetadata
public static boolean shouldShowMetadata()
-
shouldShowMessage
public static boolean shouldShowMessage()
-
shouldShowDescription
public static boolean shouldShowDescription()
-
putMetadata
public void putMetadata(String key, Object value)
put key value pair to the metadata- Parameters:
key- key of the entryvalue- value of the entry
-
toStringConditionally
public String toStringConditionally()
This method is used to construct a Status with fields conditionally.- Returns:
- JSON style String of Status
-
reload
public static void reload()
-
getConfig
public static Map<String,Object> getConfig()
This static method is very important for any customized status wrapper to get the light-4j status before customizing it. There are several organizations that have their own customized wrapper to translate the status code to something else in order to hide the real error message for security reasons.- Returns:
- a map of config entries
-
-