Handling blank body in request [ REST] while receiving it as

Posted by mdanwarh on 23-Sep-2019 11:00

Hi,

I have written my code in such a way that receiving a JSON object as prodataset in my rest program. When I am passing blank dataset [ nothing in body], I am getting the following error. My rest program is not getting called at all.

I would like to send a custom message instead of Progress Error. Something like

{

       "StatusMessage": "No request body"

}

I am getting the progress Error in log [ see below]

[19/09/23@05:58:15.902-0400] P-011028 T-009424 4 AS AS -- TRACE: cso4GL: In execCall() -  execProc() failed. (8458)

[19/09/23@05:58:15.902-0400] P-011028 T-009424 4 AS AS -- TRACE: Set open 4GL server state to 5. (8400)

[19/09/23@05:58:15.902-0400] P-011028 T-009424 4 AS AS -- TRACE: STATELESS: putting SINGLERUN proxy d6dd7952 (handle: 6204478) on the pending deletion list (8458)

[19/09/23@05:58:15.902-0400] P-011028 T-009424 4 AS AS Server Message state = MSGSTATE_SENDRESP

[19/09/23@05:58:15.902-0400] P-011028 T-009424 4 AS AS -- TRACE: Set open 4GL server state to 1. (8400)

[19/09/23@05:58:15.902-0400] P-011028 T-009424 1 AS -- Error attempting to run 'TravelerCreate TravelerCreateCrmGis.p'. JSON value of ProDataset or temp-table parameter is invalid or empty. (16992)

[19/09/23@05:58:15.902-0400] P-011028 T-009424 1 AS -- An incomplete client request. (8020)

[19/09/23@05:58:15.902-0400] P-011028 T-009424 4 AS AS -- TRACE: open4GLRead 65. (8403)

[19/09/23@05:58:15.902-0400] P-011028 T-009424 4 AS AS Server Message state = MSGSTATE_FINISHRQ

[19/09/23@05:58:15.902-0400] P-011028 T-009424 4 AS AS Server Message state = MSGSTATE_IDLE

My Rest Program:

PROCEDURE abc:

   /*------------------------------------------------------------------------------

    Purpose:

    Notes:

   ------------------------------------------------------------------------------*/

DEFINE INPUT  PARAMETER DATASET        FOR dsTravelerCreate.

.

.

.

.

CATCH e AS Progress.Lang.Error :

            MESSAGE "Inside catch 0923 Error in DAtaset".

END CATCH.

End procedure. 

Posted by egarcia on 23-Sep-2019 14:42

Hello,

> I have written my code in such a way that receiving a JSON object as prodataset in my rest program. When I am passing blank

> dataset [ nothing in body], I am getting the following error. My rest program is not getting called at all.

Here is what I think is happening.

An empty body is not a valid dataset. The validation that you see happens prior to the program being called.

The program would be called with a valid dataset.

A blank dataset would be something like the following:

{

   "dsTraveler": {

       "ttTraveler": []

   }

}

A possible way to detect the case of an empty body in the HTTP request, would be to have the procedure receive a LONGCHAR parameter and then do the conversion from string to a JSON DATASET. Here you would have a chance to catch exceptions.

I hope this helps.

Posted by Peter Judge on 23-Sep-2019 19:08

If you're using the REST transport, you may want to consider a webhandler instead. That gives you the control over what happens in such a case.

All Replies

Posted by egarcia on 23-Sep-2019 14:42

Hello,

> I have written my code in such a way that receiving a JSON object as prodataset in my rest program. When I am passing blank

> dataset [ nothing in body], I am getting the following error. My rest program is not getting called at all.

Here is what I think is happening.

An empty body is not a valid dataset. The validation that you see happens prior to the program being called.

The program would be called with a valid dataset.

A blank dataset would be something like the following:

{

   "dsTraveler": {

       "ttTraveler": []

   }

}

A possible way to detect the case of an empty body in the HTTP request, would be to have the procedure receive a LONGCHAR parameter and then do the conversion from string to a JSON DATASET. Here you would have a chance to catch exceptions.

I hope this helps.

Posted by Peter Judge on 23-Sep-2019 19:08

If you're using the REST transport, you may want to consider a webhandler instead. That gives you the control over what happens in such a case.

Posted by mdanwarh on 24-Sep-2019 08:08

Thanks for the reply. I will use LONGCHAR for my solution

This thread is closed