Rest response code

Posted by Andrew Stalker on 20-Oct-2014 06:04

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

Posted by egarcia on 02-Feb-2015 09:56

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

Posted by Ramadevi Dhavala on 20-Oct-2014 06:17

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.

Posted by Andrew Stalker on 02-Feb-2015 09:40

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

Posted by egarcia on 02-Feb-2015 09:56

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.

This thread is closed