-
Notifications
You must be signed in to change notification settings - Fork 19
Conversation
Graceful error handling with custom pages and proper fallback fix #227
@@ -97,6 +97,10 @@ async function fetch( | |||
}; | |||
} catch (e) { | |||
if (e && e.statusCode && e.statusCode === 404) { | |||
if (path.match(/^\/?404\.(md|html)$/)) { |
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 idea is that we will first do a regular bail
with the proper status code (i.e. 400
, 500
, etc.) and try to fetch the corresponding md file (400.md
, 500.md
, etc.).
If that is missing, we'll end up here again with a path that matches 404, and perform a safebail
as fallback
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.
hmm, I would do this in an/the error handler at the end of the pipe, and not in fetch.
Add unit test to verify graceful handling of missing 404.md error page fix #227
Codecov Report
@@ Coverage Diff @@
## master #326 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 46 46
Lines 965 969 +4
=====================================
+ Hits 965 969 +4
Continue to review full report at Codecov.
|
In terms of traffic control, I'd like to merge #260 first, even if we still have to discuss through a couple of issues that would affect the handling of errors (and this PR) |
@@ -97,6 +97,10 @@ async function fetch( | |||
}; | |||
} catch (e) { | |||
if (e && e.statusCode && e.statusCode === 404) { | |||
if (path.match(/^\/?404\.(md|html)$/)) { | |||
// Passing status 200 since we'll first have tried 400.html with a 404 | |||
return safebail(logger, `Could not find Markdown at ${options.uri}`, e, 200); |
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.
this is IMO wrong: you must not return a 200
. otherwise fastly doesn't know that the resource is missing and cannot fallback to static processing...which actually renders this entire feature useless :-)
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.
We can control the fallback, but it should definitely be a 404.
since we do error handling now in the dispatcher, I'll close this for now. |
Graceful error handling with custom pages and proper fallback
fix #227