fix(http): improve error logging (#18454)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
Rhys Arkins 2022-10-21 12:14:45 +02:00 committed by GitHub
parent 67043c4381
commit cdec83463c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 18 additions and 55 deletions

View file

@ -36,10 +36,7 @@ export async function fetchJSONFile(
if (err instanceof ExternalHostError) { if (err instanceof ExternalHostError) {
throw err; throw err;
} }
logger.debug( logger.debug(`Preset file ${fileName} not found in ${repo}`);
{ statusCode: err.statusCode, url: `${endpoint}${url}` },
`Failed to retrieve ${fileName} from repo`
);
throw new Error(PRESET_DEP_NOT_FOUND); throw new Error(PRESET_DEP_NOT_FOUND);
} }
if (!res.body.isLastPage) { if (!res.body.isLastPage) {

View file

@ -24,10 +24,7 @@ export async function fetchJSONFile(
if (err instanceof ExternalHostError) { if (err instanceof ExternalHostError) {
throw err; throw err;
} }
logger.debug( logger.debug(`Preset file ${fileName} not found in ${repo}`);
{ statusCode: err.statusCode, repo, fileName },
`Failed to retrieve ${fileName} from repo`
);
throw new Error(PRESET_DEP_NOT_FOUND); throw new Error(PRESET_DEP_NOT_FOUND);
} }

View file

@ -30,10 +30,7 @@ export async function fetchJSONFile(
if (err instanceof ExternalHostError) { if (err instanceof ExternalHostError) {
throw err; throw err;
} }
logger.debug( logger.debug(`Preset file ${fileName} not found in ${repo}`);
{ statusCode: err.statusCode, url },
`Failed to retrieve ${fileName} from repo`
);
throw new Error(PRESET_DEP_NOT_FOUND); throw new Error(PRESET_DEP_NOT_FOUND);
} }

View file

@ -57,10 +57,7 @@ export async function fetchJSONFile(
if (err instanceof ExternalHostError) { if (err instanceof ExternalHostError) {
throw err; throw err;
} }
logger.debug( logger.debug(`Preset file ${fileName} not found in ${repo}`);
{ statusCode: err.statusCode, url },
`Failed to retrieve ${fileName} from repo`
);
throw new Error(PRESET_DEP_NOT_FOUND); throw new Error(PRESET_DEP_NOT_FOUND);
} }

View file

@ -17,10 +17,7 @@ export async function fetchJSONFile(
throw err; throw err;
} }
logger.debug( logger.debug(`Preset file ${fileName} not found in ${repo}`);
{ err, repo, fileName },
`Failed to retrieve ${fileName} from repo ${repo}`
);
throw new Error(PRESET_DEP_NOT_FOUND); throw new Error(PRESET_DEP_NOT_FOUND);
} }

View file

@ -157,35 +157,12 @@ export async function getDependency(
} }
return dep; return dep;
} catch (err) { } catch (err) {
if (err.statusCode === 401 || err.statusCode === 403) { const ignoredStatusCodes = [401, 402, 403, 404];
logger.debug( const ignoredResponseCodes = ['ENOTFOUND'];
{ if (
packageUrl, ignoredStatusCodes.includes(err.statusCode) ||
err, ignoredResponseCodes.includes(err.code)
statusCode: err.statusCode, ) {
packageName,
},
`Dependency lookup failure: unauthorized`
);
return null;
}
if (err.statusCode === 402) {
logger.debug(
{
packageUrl,
err,
statusCode: err.statusCode,
packageName,
},
`Dependency lookup failure: payment required`
);
return null;
}
if (err.statusCode === 404 || err.code === 'ENOTFOUND') {
logger.debug(
{ err, packageName },
`Dependency lookup failure: not found`
);
return null; return null;
} }
if (uri.host === 'registry.npmjs.org') { if (uri.host === 'registry.npmjs.org') {

View file

@ -154,11 +154,6 @@ function handleGotError(
) { ) {
return err; return err;
} }
if (err.statusCode === 404) {
logger.debug({ url: path }, 'GitHub 404');
} else {
logger.debug({ err }, 'Unknown GitHub error');
}
return err; return err;
} }

View file

@ -89,6 +89,12 @@ async function gotTask<T>(
duration = duration =
error.timings?.phases.total ?? error.timings?.phases.total ??
/* istanbul ignore next: can't be tested */ 0; /* istanbul ignore next: can't be tested */ 0;
const method = options.method?.toUpperCase() ?? 'GET';
const code = error.code ?? 'UNKNOWN';
const retryCount = error.response?.retryCount ?? -1;
logger.debug(
`${method} ${url} = (code=${code}, statusCode=${statusCode} retryCount=${retryCount}, duration=${duration})`
);
} }
throw error; throw error;

View file

@ -82,7 +82,7 @@ export async function lookupUpdates(
// If dependency lookup fails then warn and return // If dependency lookup fails then warn and return
const warning: ValidationMessage = { const warning: ValidationMessage = {
topic: depName, topic: depName,
message: `Failed to look up dependency ${depName}`, message: `Failed to look up ${datasource} dependency ${depName}`,
}; };
logger.debug({ dependency: depName, packageFile }, warning.message); logger.debug({ dependency: depName, packageFile }, warning.message);
// TODO: return warnings in own field // TODO: return warnings in own field