Hi Dalsu,
Changing the default error response will require a global error policy. Note in this policy you will need a default catch at a minimum, but some errors (BadRequestError, UnauthorizedError, and ForbiddenError) will require an explicit catch. When the error is caught, the HTTP status code and reason phrase are reset to 200 OK, so you'll need to use the error object context.get('error') and reset the status code and phrase using context.message.statusCode and the values from the error object. At for the payload you can do whatever you wish. Please let me know if there are more specific questions on the message content I'm missing.
Best Regards,
Steve Linn
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
------------------------------
Original Message:
Sent: Tue July 18, 2023 12:30 AM
From: dalsu Byun
Subject: How do I change the response format of context.reject?
Hi
I want to change the response Message Format of context.reject in Gatewayscript.
1. context.reject
#GatewayScript
context.message.statusCode = "501 Custom Error";
context.reject("GWSError","Error Message");
#Response
{
"httpCode": "501",
"httpMessage": "Custom Error",
"moreInformation": "Error Message"
}
2. In case of trying to process in Global Error Policy after handling as throw Exception
#GatewayScript
throw Exception("Error Message");
#Response : Always handled as a JavaScriptError
{
"name": "JavaScriptError",
"message": "Internal Error",
"status": {
"code": 500,
"reason": "Internal Server Error"
},
"policyTitle": null
}
---------------------------------------------------
#Desired Response Format
{
"name": "Error Title",
"message": "message",
"status": {
"code": 501,
"reason": "Custom Error"
},
"policyTitle": null
}
------------------------------
dalsu Byun
------------------------------