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) {
throw err;
}
logger.debug(
{ statusCode: err.statusCode, url: `${endpoint}${url}` },
`Failed to retrieve ${fileName} from repo`
);
logger.debug(`Preset file ${fileName} not found in ${repo}`);
throw new Error(PRESET_DEP_NOT_FOUND);
}
if (!res.body.isLastPage) {

View file

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

View file

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

View file

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

View file

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

View file

@ -157,35 +157,12 @@ export async function getDependency(
}
return dep;
} catch (err) {
if (err.statusCode === 401 || err.statusCode === 403) {
logger.debug(
{
packageUrl,
err,
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`
);
const ignoredStatusCodes = [401, 402, 403, 404];
const ignoredResponseCodes = ['ENOTFOUND'];
if (
ignoredStatusCodes.includes(err.statusCode) ||
ignoredResponseCodes.includes(err.code)
) {
return null;
}
if (uri.host === 'registry.npmjs.org') {

View file

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

View file

@ -89,6 +89,12 @@ async function gotTask<T>(
duration =
error.timings?.phases.total ??
/* 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;

View file

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