-
Notifications
You must be signed in to change notification settings - Fork 9.5k
core: create flag to prevent fatal error on bad status code #15494
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
Changes from 4 commits
6043bf7
ee725e4
36daa38
46d9b28
2f5c676
352e661
9282be7
1674f51
b413f72
079bbc8
ee48649
4dcea8f
b5062f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,10 @@ function makeNetworkRequest() { | |
describe('#getNetworkError', () => { | ||
/** | ||
* @param {NetworkRequest=} mainRecord | ||
* @param {{warnings: Array<string | LH.IcuMessage>, ignoreStatusCode?: LH.Config.Settings['ignoreStatusCode']}=} context | ||
*/ | ||
function getAndExpectError(mainRecord) { | ||
const error = getNetworkError(mainRecord); | ||
function getAndExpectError(mainRecord, context) { | ||
const error = getNetworkError(mainRecord, {warnings: [], ...context}); | ||
if (!error) throw new Error('expected a network error'); | ||
return error; | ||
} | ||
|
@@ -42,7 +43,7 @@ describe('#getNetworkError', () => { | |
const url = 'http://the-page.com'; | ||
const mainRecord = makeNetworkRequest(); | ||
mainRecord.url = url; | ||
expect(getNetworkError(mainRecord)).toBeUndefined(); | ||
expect(getNetworkError(mainRecord, {warnings: []})).toBeUndefined(); | ||
}); | ||
|
||
it('fails when page fails to load', () => { | ||
|
@@ -66,15 +67,41 @@ describe('#getNetworkError', () => { | |
expect(error.friendlyMessage).toBeDisplayString(/^Lighthouse was unable to reliably load/); | ||
}); | ||
|
||
it('fails when page returns with a 404', () => { | ||
it('warns when page returns with a 404 with flag', () => { | ||
const url = 'http://the-page.com'; | ||
const mainRecord = makeNetworkRequest(); | ||
mainRecord.url = url; | ||
mainRecord.statusCode = 404; | ||
const error = getAndExpectError(mainRecord); | ||
const context = { | ||
url, | ||
networkRecords: [mainRecord], | ||
warnings: [], | ||
loadFailureMode: LoadFailureMode.warn, | ||
ignoreStatusCode: true, | ||
}; | ||
|
||
const error = getNetworkError(mainRecord, context); | ||
expect(error).toBeUndefined(); | ||
expect(context.warnings[0]).toBeDisplayString(/^Lighthouse was unable to reliably load/); | ||
}); | ||
|
||
it('fails when page returns with a 404 without flag', () => { | ||
const url = 'http://the-page.com'; | ||
const mainRecord = makeNetworkRequest(); | ||
mainRecord.url = url; | ||
mainRecord.statusCode = 404; | ||
const context = { | ||
url, | ||
networkRecords: [mainRecord], | ||
warnings: [], | ||
loadFailureMode: LoadFailureMode.warn, | ||
}; | ||
|
||
const error = getAndExpectError(mainRecord, context); | ||
expect(error).toBeDefined(); | ||
expect(error.message).toEqual('ERRORED_DOCUMENT_REQUEST'); | ||
expect(error.code).toEqual('ERRORED_DOCUMENT_REQUEST'); | ||
expect(error.friendlyMessage).toBeDisplayString(/^Lighthouse was unable to reliably load.*404/); | ||
expect(error.friendlyMessage).toBeDisplayString(/^Lighthouse was unable to reliably load/); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 404 is important IMO, otherwise this could pass for one of the non-status code related page load errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would also likely be helpful to add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FWIW the bad status code is also tracked by our |
||
}); | ||
|
||
it('fails when page returns with a 500', () => { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 should generalize this to all error status codes (4xx/5xx). So I think it's better to use this
mainRecord.hasErrorStatusCode()
block instead of doing a=== 404
check.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.
does generalizing this to include all error status codes change our initial thoughts on the defaults? or do they feel good still?
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.
I think the defaults should be the same as we discussed