Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (!metadata.versions.includes(this.params.version)) {
return this.ctx.body = {
status: 404,
message: `Couldn't find version ${this.params.version} for ${this.params.name}. Make sure you use a specific version number, and not a version range or an npm tag.`,
};
}
}
try {
this.ctx.body = await this.getFiles(); // Can't use AsJson() version here because we need to set correct status code on cached errors.
this.ctx.maxAge = v1Config.maxAgeStatic;
this.ctx.maxStale = v1Config.maxStaleStatic;
} catch (error) {
if (error instanceof got.RequestError || error instanceof got.TimeoutError) {
return this.ctx.status = error.code === 'ETIMEDOUT' ? 504 : 502;
} else if (error instanceof got.HTTPError) {
return this.ctx.body = {
status: error.response.statusCode || 502,
message: error.response.body,
};
}
throw error;
}
}
send(safeLocal(localize, prefix, "parse_error", type));
} else if (error instanceof got.HTTPError) {
if (error.statusCode.startsWith("4")) {
send(safeLocal(localize, prefix, "4xx_error", type, error.statusCode));
} else if (error.statusCode.startsWith("5")) {
send(safeLocal(localize, prefix, "5xx_error", type, error.statusCode));
} else {
send(safeLocal(localize, prefix, "http_error", type, error.statusCode));
}
} else if (error instanceof got.MaxRedirectsError) {
send(safeLocal(localize, prefix, "redirect_error", type));
} else if (error instanceof got.UnsupportedProtocolError) {
send(safeLocal(localize, prefix, "protocol_error", type));
} else if (error instanceof got.CancelError) {
send(safeLocal(localize, prefix, "cancel_error", type));
} else if (error instanceof got.TimeoutError) {
send(safeLocal(localize, prefix, "timeout_error", type));
} else {
send(safeLocal(localize, prefix, "generic_error", type));
}
}