idoshamun
idoshamun

Reputation: 1135

Returning error object along with the hapijs boom object

I'm trying to return the error object inside the response of a boom internal error object but it keeps omitting the error object. I tried to follow the answer here but it didn't help.

function (request, reply) {

    options.healthCheck(function (err) {

        if (!err) {
            return reply('I\'m healthy!!!');
        }

        var boomErr = boom.internal('I don\'t feel so good', {
            err: err
        });
        boomErr.output.payload.details = err;
        return reply(boomErr);
    });
}

Here is the response:

{  
   "statusCode":500,
   "error":"Internal Server Error",
   "message":"An internal server error occurred",
   "details":{  }
}

Upvotes: 1

Views: 2874

Answers (1)

idoshamun
idoshamun

Reputation: 1135

After digging into boom docs, I found out that all 5xx errors hide the custom message and payload. Switching to bad request error solved my issue.

Upvotes: 3

Related Questions