Skip to content

Commit

Permalink
Merge pull request #371 from metrico/basic_auth_fix_369
Browse files Browse the repository at this point in the history
Basic auth fix 369
  • Loading branch information
akvlad authored Oct 31, 2023
2 parents 72ab409 + d3b0beb commit a7360ea
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 172 deletions.
1 change: 1 addition & 0 deletions lib/bun_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const wrapper = (handler, parsers) => {
response = result
}
if (response instanceof Object && typeof response !== 'string' && !Buffer.isBuffer(response)) {
headers['Content-Type'] = 'application/json'
response = JSON.stringify(response)
}
return new Response(response, { status: status, headers: headers })
Expand Down
7 changes: 7 additions & 0 deletions lib/handlers/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ const handler = (err, req, res) => {
message: err.message
})
}
if (err.name && err.name === 'UnauthorizedError') {
return res.status(401).send({
statusCode: 401,
error: 'Unauthorized',
message: err.message
})
}
asyncLogError(err, req.log)
return res.status(500).send({
statusCode: 500,
Expand Down
Loading

0 comments on commit a7360ea

Please sign in to comment.