Class 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
    • 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 Code
        args - 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 Code
        args - A list of arguments that will be populated into the error description
        metadata - 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 Code
        code - Code
        message - Message
        description - 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 - HttpStatus
        message - Message
        description - 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 Code
        code - Code
        severity - Status Severity
        message - Message
        description - 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()
      • setMetadata

        public void setMetadata​(Map<String,​Object> metadata)
      • 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 entry
        value - 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