Handle GWS REST server errors

When a call to a Genero Web Services REST function returns a status, you can check for server errors.

The error codes described in the "responses" section of the OpenAPI specification file are generated as constants on the client stub. You can reference these to trap errors in your code.

In this example constants are generated from the error name or description in the OpenAPI specification for the function.

responses generated in client stub by fglrestful

# Error codes
PUBLIC CONSTANT C_SUCCESS = 0
PUBLIC CONSTANT C_DIVISION_BY_ZERO = 1001
PUBLIC CONSTANT C_MYERROR = 1002

PUBLIC DEFINE myerror RECORD ATTRIBUTE(XMLName='myerror')
              code INTEGER ATTRIBUTE(XMLName='code'),
              reason STRING ATTRIBUTE(XMLName='reason')
       END RECORD

Trapping server errors on the client side

IMPORT FGL clientStub

# ... function code performing call to the client stub function ... 
FUNCTION myWSRESTcall()
    DEFINE retI INTEGER
    DEFINE wsstatus INTEGER

    CALL clientStub.Div(8, 2) RETURNING wsstatus, retI

    CASE wsstatus
        WHEN clientStub.C_SUCCESS
            DISPLAY "Div result :", retI
        WHEN clientStub.C_DIVISION_BY_ZERO
            DISPLAY "Division by Zero"
        WHEN clientStub.C_MYERROR
            DISPLAY clientStub.myError.*
        OTHERWISE
            DISPLAY "Unexpected error :", wsstatus
    END CASE
END FUNCTION 
It is recommended to always handle unexpected errors (CASE OTHERWISE in the code example), as these may arise due to different transport layers.