KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method: Get HTTP Status Code Type
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: December 9, 2011

Here is a method that can be used to get the Type of an HTTP Status Code. This information is based on RFC 2616.

Note: HTTP makes the distinction between success and failure based on status code "groups", which are just ranges of values. Thus the only codes that are considered errors are those that fall in the Client or Server Error range.

// Error codes and messages are defined in RFC 2616:
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

C_LONGINT($1;$status_l)

C_TEXT($0;$type_t)

$status_l:=$1

Case of
    // Information Codes
   : (($status_l>=100) & ($status_l<200))
      $type_t:="Information Code"

    // Success Codes
   : (($status_l>=200) & ($status_l<300))
      $type_t:="Success Code"

    // Redirection Codes
   : (($status_l>=300) & ($status_l<400))
      $type_t:="Redirection Code"

    // Client Error Codes
   : (($status_l>=400) & ($status_l<500))
      $type_t:="Client Error Code"

    // Server Error Codes
   : (($status_l>=500) & ($status_l<600))
      $type_t:="Server Error Code"

Else
      $type_t:="Unknown status type."
End case

$0:=$type_t