14-12-23 06:39 PM
Hi,
With a postman PUT request, our server returns a JSON response with an error code and error message for a HTTP status code 400 like below:
However when I do the same PUT request with Utility - HTTP VBO::HTTP Request, it just returns JSON response as a string containing "Request Failed:The remote server returned an error: (400) Bad Request." and not the JSON itself.. Any idea why it's like that?
Thanks in Advance
Raghav
Answered! Go to Answer.
18-12-23 03:34 PM
Because that's the way the Utility - HTTP VBO is currently designed. If you open the Code stage associated with the HTTP Request action and scroll towards the bottom, you'll see where a normal (aka successful) request is handled. You'll also see where WebException is handled in the Catch block. The 400 error you're receiving is being handled within that Catch block - within the section highlighted in the red block.
There's a couple things that can be done here. To address your immediate needs, you could add something like this within that If block after the line resultData = e.Message:
Dim responseStream As IO.Stream = e.Response.GetResponseStream()
Dim sr As New IO.StreamReader(responseStream)
resultData = resultData + " " + sr.ReadToEnd()
This should append the raw JSON body to the exception message output. Then it's just a matter of parsing it out in the containing process/object.
NOTE: I haven' tested the code above, but I'm fairly confident it will work for you. 😁
Additionally, you can raise an Idea on the DX Ideas board to have the VBO updated to return any contents within the response body if the response type is a WebException.
Cheers,
18-12-23 03:34 PM
Because that's the way the Utility - HTTP VBO is currently designed. If you open the Code stage associated with the HTTP Request action and scroll towards the bottom, you'll see where a normal (aka successful) request is handled. You'll also see where WebException is handled in the Catch block. The 400 error you're receiving is being handled within that Catch block - within the section highlighted in the red block.
There's a couple things that can be done here. To address your immediate needs, you could add something like this within that If block after the line resultData = e.Message:
Dim responseStream As IO.Stream = e.Response.GetResponseStream()
Dim sr As New IO.StreamReader(responseStream)
resultData = resultData + " " + sr.ReadToEnd()
This should append the raw JSON body to the exception message output. Then it's just a matter of parsing it out in the containing process/object.
NOTE: I haven' tested the code above, but I'm fairly confident it will work for you. 😁
Additionally, you can raise an Idea on the DX Ideas board to have the VBO updated to return any contents within the response body if the response type is a WebException.
Cheers,