Rest response code - Forum - Mobile - Progress Community

Rest response code

 Forum

Rest response code

This question is answered

How do you change the response http status code for a rest service.

e.g. on catching an error I want to return Internal Error 500 rather than 200 ok

Verified Answer
  • Hello,

    Are you using a REST Service or a Mobile Service?

    If you are using a REST Service, you can use Edit on the service (from Defined Services) and map an output parameter to Response Code in the HTTP message.

    If you are using a Mobile Service, you do not need to do any mapping.

    Instead, you can raise an error in the method using one the following statements:

    - RETURN ERROR New Progress.Lang.AppError("RETURN ERROR AppError: TEST ERROR").          

    -  RETURN ERROR "TEST".

    - UNDO, THROW NEW Progress.Lang.AppError("RETURN ERROR AppError: TEST ERROR").

    The convention is that the server will return error 500 and the JSON response would include the error.

    I hope this helps.

All Replies
  • Hi,

    In the .p/.cls file that is used in mapping, define an Integer Output variable and assign the status code value 500 (or any status code value of your choice) to it. In the rest mapper, map the output Interface parameter to Response Code element of Http Message. Accessing the rest service will result in Status Code: 500 Internal Server Error.

    Hope this helps.

    Thanks&Regards,

    Rama.

  • That make sense. How do you set the resonse code element of a HTTP message?

  • Hello,

    Are you using a REST Service or a Mobile Service?

    If you are using a REST Service, you can use Edit on the service (from Defined Services) and map an output parameter to Response Code in the HTTP message.

    If you are using a Mobile Service, you do not need to do any mapping.

    Instead, you can raise an error in the method using one the following statements:

    - RETURN ERROR New Progress.Lang.AppError("RETURN ERROR AppError: TEST ERROR").          

    -  RETURN ERROR "TEST".

    - UNDO, THROW NEW Progress.Lang.AppError("RETURN ERROR AppError: TEST ERROR").

    The convention is that the server will return error 500 and the JSON response would include the error.

    I hope this helps.