mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-14 16:46:25 +00:00
1013302e0f
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { ExternalHostError } from '../../types/errors/external-host-error';
|
|
import { Http } from '../../util/http';
|
|
import type { HttpError } from '../../util/http';
|
|
import type {
|
|
DatasourceApi,
|
|
DigestConfig,
|
|
GetReleasesConfig,
|
|
RegistryStrategy,
|
|
ReleaseResult,
|
|
} from './types';
|
|
|
|
export abstract class Datasource implements DatasourceApi {
|
|
protected constructor(public readonly id: string) {
|
|
this.http = new Http(id);
|
|
}
|
|
|
|
caching: boolean | undefined;
|
|
|
|
customRegistrySupport = true;
|
|
|
|
defaultConfig: Record<string, unknown> | undefined;
|
|
|
|
defaultRegistryUrls?: string[] | (() => string[]);
|
|
|
|
defaultVersioning?: string | undefined;
|
|
|
|
registryStrategy: RegistryStrategy | undefined = 'first';
|
|
|
|
protected http: Http;
|
|
|
|
abstract getReleases(
|
|
getReleasesConfig: GetReleasesConfig
|
|
): Promise<ReleaseResult | null>;
|
|
|
|
getDigest?(config: DigestConfig, newValue?: string): Promise<string | null>;
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
handleSpecificErrors(err: HttpError): void {}
|
|
|
|
protected handleGenericErrors(err: HttpError): never {
|
|
// istanbul ignore if: not easy testable with nock
|
|
if (err instanceof ExternalHostError) {
|
|
throw err;
|
|
}
|
|
this.handleSpecificErrors(err);
|
|
if (err.response?.statusCode !== undefined) {
|
|
if (
|
|
err.response?.statusCode === 429 ||
|
|
(err.response?.statusCode >= 500 && err.response?.statusCode < 600)
|
|
) {
|
|
throw new ExternalHostError(err);
|
|
}
|
|
}
|
|
throw err;
|
|
}
|
|
}
|