-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow custom headers to be set for default error responses #34
Conversation
@@ -501,7 +510,7 @@ module.exports = async (request, response, config = {}, methods = {}) => { | |||
try { | |||
relativePath = decodeURIComponent(url.parse(request.url).pathname); | |||
} catch (err) { | |||
return sendError(response, acceptsJSON, current, handlers, config, { | |||
return sendError('/', response, acceptsJSON, current, handlers, config, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The absolutePath
is not defined here yet, so we need to supply a placeholder.
type: 'inline' | ||
}) | ||
}; | ||
let defaultHeaders = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could also destructure to the existing const variable but that's a bit ugly 🤷♂️
src/index.js
Outdated
response.setHeader('Content-Type', 'text/html; charset=utf-8'); | ||
const headers = await getHeaders(config.headers, current, absolutePath, null); | ||
|
||
response.writeHead(statusCode, Object.assign(headers, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why assign? You are modifying the headers anyway if you do this. Do you want to modify the original object?
Perhaps you want to do:
Object.assign({}, headers, {...})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
Codecov Report
@@ Coverage Diff @@
## master #34 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 1 1
Lines 281 285 +4
=====================================
+ Hits 281 285 +4
Continue to review full report at Codecov.
|
Previously, custom headers were not applied to all error responses, only for
.html
pages.Once this is merged, they will also be applied to the default error renderings.