In PeopleSoft, working with Integration Broker (IB) to make REST or SOAP service calls is pretty standard. But here's the thing—you can't just wrap everything in a simple Try-Catch
and call it a day.
Why? Because the moment the target system returns a non-200 HTTP status—say a 400 Bad Request
—PeopleSoft doesn’t raise an exception you can catch. Instead, the system treats it as a failure at the ResponseStatus
level, but still gives you a chance to inspect the response.
So if you don’t handle that explicitly, you’re flying blind.
Problem Statement
Let’s say you make a REST call to an external service that returns a 400
due to some client-side validation issue (e.g., missing field, invalid format).
In Postman, you'd see a well-structured JSON or XML body explaining the error.
But in PeopleCode?
If you don’t handle the response carefully, you'll just see that the SyncRequest()
failed and your code crashes or logs a vague failure.
Solution: Don’t Just Use Try-Catch
. Check ResponseStatus
.
Here’s a reliable pattern:
Why GetContentString()
Matters Even on Failure
The key insight: even when PeopleSoft sees the status as a failure, the response content (body) is still available.
This is critical when calling modern REST APIs. Most services return detailed JSON error bodies like:
Without grabbing GetContentString()
, you lose all of this.
But Wait—Why Not Just Use Try-Catch
?
Here’s the catch (no pun intended): Try-Catch
in PeopleCode will not trap the HTTP 400-style errors unless the system throws an internal PeopleSoft exception (like a message catalog error, null pointer, etc.)
In the case of a REST response with a non-2xx status:
-
SyncRequest()
still returns a validMessage
object -
You must inspect
ResponseStatus
manually -
Try-Catch
won’t help unless something else breaks
Suggested Practice
Always wrap your IB call like this:
-
Make the request
-
Check
ResponseStatus
-
Use
GetContentString()
even on failure -
Log or parse the error for better diagnostics
-
Use
IBException
to catch IB-side errors
Bonus Tip: Log to a Custom Table
Instead of just using MessageBox
, you can log everything to a custom error log table, like so:
Final Thoughts
If you're calling external APIs from PeopleSoft, expect failure. Not because your code is bad—but because that’s how real-world APIs work.
So don’t treat 400
, 404
, 500
, etc. as fatal errors. Treat them as data. Read the response, log it, act on it.
And always remember: GetContentString()
is your friend—even when the server isn't.
Let me know if you want to expand this with JSON parsing, XML fault extraction, or a reusable logging function.
No comments:
Post a Comment