From cac7aa2beea3c75c0acf4ce03f509f336458ebfd Mon Sep 17 00:00:00 2001 From: Frank Noirot Date: Tue, 20 May 2025 19:21:53 -0400 Subject: [PATCH] Optionally chain `error_code` Something in the Chamfer E2E tests is complaining about an uncaught error with `error_code` trying to be referenced on something that is `undefined`. That means that an API request is coming back as not successful but does not have an actual error in the body of the response. --- src/lang/std/engineConnection.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lang/std/engineConnection.ts b/src/lang/std/engineConnection.ts index df07c02aa..bcba3143c 100644 --- a/src/lang/std/engineConnection.ts +++ b/src/lang/std/engineConnection.ts @@ -998,7 +998,7 @@ class EngineConnection extends EventTarget { if (!message.success) { const errorsString = message?.errors ?.map((error) => { - return ` - ${error.error_code}: ${error.message}` + return ` - ${error?.error_code || 'Unknown error'}: ${error?.message || 'Unknown message'}` }) .join('\n') if (message.request_id) { @@ -1016,7 +1016,7 @@ class EngineConnection extends EventTarget { } const firstError = message?.errors[0] - if (firstError.error_code === 'auth_token_invalid') { + if (firstError?.error_code === 'auth_token_invalid') { this.state = { type: EngineConnectionStateType.Disconnecting, value: { @@ -1030,7 +1030,7 @@ class EngineConnection extends EventTarget { this.disconnectAll() } - if (firstError.error_code === 'internal_api') { + if (firstError?.error_code === 'internal_api') { this.state = { type: EngineConnectionStateType.Disconnecting, value: {