Hello, i am doing http_string call as follow
Monitor;
result = http_string( 'POST': url: postdata: 'application/json')
On-Error *ALL;
If result <> ' ';
...
EndIf;
EndMon;
When there these is issue in the message i am sending, it raises exception and control goes to On-Error section and result field does not have any data. When i look at log there is failure cause returned from server :{"code":"S0001","message":["#/customs_form/customs_items/0/quantity: failed sche", i want to read this error message inside my program, please help how to do that?
Log:
senddoc(): entered
{ "request_id" : "F90-0000000092", "order_number" : "OOGP0007552362", "from_addr
recvresp(): entered
HTTP/1.1 422 Unprocessable Entity
Server: nginx/1.19.0
Date: Fri, 18 Mar 2022 19:14:38 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
SetError() #13: HTTP/1.1 422 Unprocessable Entity
recvresp(): end with 422
recvdoc parms: chunked 0
header_load_cookies() entered
recvchunk(): entered
get_chunk_size(): entered
b7
chunk size = 183
get_chunk_size returned 183
calling comm_blockread
{"code":"S0001","message":["#/customs_form/customs_items/0/quantity: failed sche
comm_blockread returned 183
http_string not returning failure details
-
- Site Admin
- Posts: 872
- Joined: Sun Jul 04, 2021 5:12 am
Re: http_string not returning failure details
You could try calling http_req() to see if that works better for you.
Re: http_string not returning failure details
http_req looks right option for me but little issue not able to figure out.
http_req expecting a variable in result string of type char with varying which i did. After i get result, i am using yajl_buf_load_tree to parse the value.
D rtnVal s 99999A varying
rc = http_req( 'POST': url: *omit : rtnVal : *omit : postdata)
JdsNode = yajl_buf_load_tree(%Addr(rtnVal) : %Len(rtnVal):
JdsRerr);
Error returns to JdsRerr --- parse error: premature EOF
http_req expecting a variable in result string of type char with varying which i did. After i get result, i am using yajl_buf_load_tree to parse the value.
D rtnVal s 99999A varying
rc = http_req( 'POST': url: *omit : rtnVal : *omit : postdata)
JdsNode = yajl_buf_load_tree(%Addr(rtnVal) : %Len(rtnVal):
JdsRerr);
Error returns to JdsRerr --- parse error: premature EOF
Re: http_string not returning failure details
I have made it to work by defining another fixed length character variable and moving data from rtnVal to this field and use it in call to yajl_buf_load_tree and is working but want to avoid this extra steps?
D result s 99999A Inz
D rtnVal s 99999A varying
rc = http_req( 'POST': url: *omit : rtnVal : *omit : postdata)
result = rtnVal;
JdsNode = yajl_buf_load_tree(%Addr(result) : %Len(%Trim(result)):
JdsRerr);
D result s 99999A Inz
D rtnVal s 99999A varying
rc = http_req( 'POST': url: *omit : rtnVal : *omit : postdata)
result = rtnVal;
JdsNode = yajl_buf_load_tree(%Addr(result) : %Len(%Trim(result)):
JdsRerr);
-
- Site Admin
- Posts: 872
- Joined: Sun Jul 04, 2021 5:12 am
Re: http_string not returning failure details
A simpler solution is to load the tree from a string (rather than the memory buffer that is used under the covers to store your string data):
But if you absolutely must use a buffer (for example, to deal with data larger than 2mb) then you need to make sure you're getting a pointer to the data in your buffer rather than the length.
But, I think loading from a string is much cleaner. Also, I would highly discourage you from using %TRIM.
Code: Select all
rc = http_req( 'POST': url: *omit : rtnVal : *omit : postdata)
JdsNode = yajl_string_load_tree(rtnVal: JdsRerr):
Code: Select all
rc = http_req( 'POST': url: *omit : rtnVal : *omit : postdata)
JdsNode = yajl_buf_load_tree(%Addr(rtnVal:*data) : %Len(rtnVal): JdsRerr);
Re: http_string not returning failure details
Works perfectly, thanks for help.