fix(design): preserve command outcome certainty
This commit is contained in:
1 parent
4d8b19eeb5
commit
a16dfd0d6f
15 files changed
+576
-23
No files matched your search
+14
-1
@@ -112,14 +112,23 @@ async function parseResponse<T>(response: Response): Promise<T> {
|
||||
if (!response.ok) {
|
||||
let message = `${response.status} ${response.statusText}`;
|
||||
let backendCode: string | undefined;
|
||||
let commandOutcome: string | undefined;
|
||||
try {
|
||||
const payload = await response.json() as { error?: string; code?: unknown };
|
||||
const payload = await response.json() as {
|
||||
error?: string;
|
||||
code?: unknown;
|
||||
commandOutcome?: unknown;
|
||||
};
|
||||
if (payload?.error) {
|
||||
message = payload.error;
|
||||
}
|
||||
if (typeof payload?.code === 'string' && /^[a-z][a-z0-9_]{0,63}$/u.test(payload.code)) {
|
||||
backendCode = payload.code;
|
||||
}
|
||||
if (payload?.commandOutcome === 'definitive_failure'
|
||||
|| payload?.commandOutcome === 'unknown') {
|
||||
commandOutcome = payload.commandOutcome;
|
||||
}
|
||||
} catch {
|
||||
// ignore body parse failure
|
||||
}
|
||||
@@ -127,6 +136,7 @@ async function parseResponse<T>(response: Response): Promise<T> {
|
||||
source: 'browser-fallback',
|
||||
status: response.status,
|
||||
...(backendCode ? { backendCode } : {}),
|
||||
...(commandOutcome ? { commandOutcome } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -155,6 +165,9 @@ function createProxyHttpError(data: HostApiProxyData): Error {
|
||||
return normalizeAppError(new Error(message), {
|
||||
status: data.status,
|
||||
...(payload && typeof payload.code === 'string' ? { backendCode: payload.code } : {}),
|
||||
...(payload?.commandOutcome === 'definitive_failure' || payload?.commandOutcome === 'unknown'
|
||||
? { commandOutcome: payload.commandOutcome }
|
||||
: {}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user