Don't revert to regular pull if delta server 401

If the Supervisor receives a 401 Unauthorized from the delta server
when requesting a delta image location, we should surface the error
instead of falling back to a regular pull immediately, as there could
be an issue with the delta auth token, which refreshes after
DELTA_TOKEN_TIMEOUT (10min), or some other edge case.

Change-type: patch
Signed-off-by: Christina Ying Wang <christina@balena.io>
This commit is contained in:
Christina Ying Wang 2025-02-24 16:17:15 -08:00
parent b6f0ecba18
commit 2dc9d275b1

View File

@ -219,9 +219,17 @@ export async function fetchDeltaWithProgress(
}
break;
case 3:
// If 400s status code, throw a more specific error & revert immediately to a regular pull
// If 400s status code, throw a more specific error & revert immediately to a regular pull,
// unless the code is 401 Unauthorized, in which case we should surface the error by retrying
// the delta server request, instead of falling back to a regular pull immediately.
if (res.statusCode >= 400 && res.statusCode < 500) {
throw new DeltaServerError(res.statusCode, res.statusMessage);
if (res.statusCode === 401) {
throw new Error(
`Got ${res.statusCode} when requesting an image from delta server: ${res.statusMessage}`,
);
} else {
throw new DeltaServerError(res.statusCode, res.statusMessage);
}
}
if (res.statusCode !== 200) {
throw new Error(