This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(warn): http warning headers now logged
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict' | ||
|
||
const LRU = require('lru-cache') | ||
|
||
const WARNING_REGEXP = /^\s*(\d{3})\s+(\S+)\s+"(.*)"\s+"([^"]+)"/ | ||
const BAD_HOSTS = new LRU({ max: 50 }) | ||
|
||
module.exports = checkWarnings | ||
function checkWarnings (res, registry, opts) { | ||
if (res.headers.has('warning') && !BAD_HOSTS.has(registry)) { | ||
const warnings = {} | ||
res.headers.raw()['warning'].forEach(w => { | ||
const match = w.match(WARNING_REGEXP) | ||
if (match) { | ||
warnings[match[1]] = { | ||
code: match[1], | ||
host: match[2], | ||
message: match[3], | ||
date: new Date(match[4]) | ||
} | ||
} | ||
}) | ||
BAD_HOSTS.set(registry, true) | ||
if (warnings['199'] && warnings['199'].message.match(/ENOTFOUND/)) { | ||
opts.log.warn('registry', `Using stale data from ${registry} because the host is inaccessible -- are you offline?`) | ||
} else if (warnings['199']) { | ||
opts.log.warn('registry', `Unexpected warning for ${registry}: ${warnings['199'].message}`) | ||
} else if (warnings['111']) { | ||
// 111 Revalidation failed -- we're using stale data | ||
opts.log.warn( | ||
'registry', | ||
`Using stale package data from ${registry} due to a request error during revalidation.` | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters