Encountered "Converting circular structure to JSON error" when returning the customized BoomError response through server onPreResponse #4440
Labels
support
Questions, discussions, and general support
Support plan
Context
How can we help?
Problem Description
This error happened when we were using
joi
for schema validation through the validation function provided by hapi.When we used the following way to throw an error when validation failed, it threw 500 internal server error when clients gave null value of
refId
twice or above (first time didn't have the 500 internal server error but 400 bad request which was expected).Investigation
This is our error plugin which handles Boom error
index.js (error plugin)
BoomError.js
BoomError
model gets the 'data' from the response and then put it forBaseError
BaseError.js
BaseError
returns the data as a part ofbody
After doing some tracking, the error "Converting circular structure to JSON error" happened when executing
await internals.marshal(response);
in the transmit.js of hapi/lib as shown below.Finally, I found it seems it's related to #4229 failAction: detailedError to log, defaultError to response of the release 21.0.0
In the
validation.js
file,data
field ofdefaultError
will be different between the first and second triggering of joi validation.First triggering, data was null
Second triggering, data was not null but we started getting 500 internal server error
Third triggering, data was not null but seems with circular structure (I guess that's why we got "Converting circular structure to JSON error")
I would like to know why this happened and if we can fix this issue on our side, or hapi will also deal with this issue?
The text was updated successfully, but these errors were encountered: