surface Docker Hub OIDC error responses

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2026-07-27 17:13:47 +02:00
parent abd2ef45e7
commit 2aa1edee0b
2 changed files with 20 additions and 19 deletions
+11 -16
View File
@@ -108,24 +108,19 @@ const handleResponse = async (resp: httpm.HttpClientResponse): Promise<string> =
};
const parseError = (statusCode: number, body: string): Error => {
if (body) {
let errResp: unknown;
try {
errResp = JSON.parse(body);
} catch {
errResp = undefined;
}
if (errResp !== undefined) {
throw new Error(`Docker Hub API: bad status code ${statusCode}: ${JSON.stringify(errResp)}`);
}
}
if (statusCode === 401) {
throw new Error(`Docker Hub API: operation not permitted`);
}
if (body) {
const errResp = parseErrorBody(body);
for (const k of ['description', 'message', 'detail', 'error']) {
if (errResp[k]) {
throw new Error(`Docker Hub API: bad status code ${statusCode}: ${errResp[k]}`);
}
}
}
throw new Error(`Docker Hub API: bad status code ${statusCode}`);
};
const parseErrorBody = (body: string): Record<string, string> => {
try {
return <Record<string, string>>JSON.parse(body);
} catch {
return {};
}
};