Capturing HTTP 400/500 responses
Posted: Mon Apr 11, 2022 4:07 pm
I'm doing a POST operation to consume an API, and capturing the response:
I also have a monitor on there for an error.
Everything works great with an HTTP 200 response. I get the response as I'm expecting it.
But if the API fails validation, they send back an HTTP 400. How can I capture the error details?
I ran it in debug mode, it hits the on-error but I checked response and didn't see data in the field.
I set http_debug to *ON and it captures the details here. Here's an example.
Would welcome any suggestions on how to get this so I can at least log it in our log PF instead of going to each debug log file.
Code: Select all
response = http_string('POST':URL:json:'application/json');
Everything works great with an HTTP 200 response. I get the response as I'm expecting it.
But if the API fails validation, they send back an HTTP 400. How can I capture the error details?
I ran it in debug mode, it hits the on-error but I checked response and didn't see data in the field.
I set http_debug to *ON and it captures the details here. Here's an example.
Would welcome any suggestions on how to get this so I can at least log it in our log PF instead of going to each debug log file.
Code: Select all
SetError() #13: HTTP/1.1 400 Bad Request
recvresp(): end with 400
recvdoc parms: identity 1083
header_load_cookies() entered
recvdoc(): entered
SetError() #0:
recvdoc(): Receiving 1083 bytes.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>SyntaxError: Unexpected token . in JSON at position 193<br> at JSON.parse (<anonymous>)<br> at parse (/home/ubuntu/services/http-integration-service/source/node_modules/body-parser/lib/types/json.js:89:19)<br> at /home/ubuntu/services/http-integration-service/source/node_modules/body-parser/lib/read.js:121:18<br> at invokeCallback (/home/ubuntu/services/http-integration-service/source/node_modules/raw-body/index.js:224:16)<br> at done (/home/ubuntu/services/http-integration-service/source/node_modules/raw-body/index.js:213:7)<br> at IncomingMessage.onEnd (/home/ubuntu/services/http-integration-service/source/node_modules/raw-body/index.js:273:7)<br> at IncomingMessage.emit (events.js:412:35)<br> at endReadableNT (internal/streams/readable.js:1334:12)<br> at processTicksAndRejections (internal/process/task_queues.js:82:21)</pre>
</body>
</html>