Skip to content
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

Merged
merged 3 commits into from
Jul 5, 2018
Merged

Conversation

leo
Copy link
Contributor

@leo leo commented Jul 5, 2018

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.

@leo leo added the enhancement New feature or request label Jul 5, 2018
@leo leo requested a review from OlliV July 5, 2018 18:43
@@ -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, {
Copy link
Contributor Author

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 = {};
Copy link

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, {
Copy link

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, {...})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

@codecov
Copy link

codecov bot commented Jul 5, 2018

Codecov Report

Merging #34 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #34   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           1      1           
  Lines         281    285    +4     
=====================================
+ Hits          281    285    +4
Impacted Files Coverage Δ
src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0c65161...072df14. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants