cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP Utility VBO doesn't return JSON when status code is 400

rpatchip
Staff
Staff

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:

{
    "code": 400,
    "message": "error description here",
    "errorDetails": "",
    "causeException": "",
    "causeStack": [],
    "internalDetails": "",
    "path": "path here",
    "requestId": "f5f73b"
}

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?

35970.png

Thanks in Advance

Raghav

1 BEST ANSWER

Helpful Answers

ewilson
Staff
Staff

@rpatchip,

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.

35969.png

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,

View answer in original post

1 REPLY 1

ewilson
Staff
Staff

@rpatchip,

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.

35969.png

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,