From b99897dca41360a5dc69aa3269339acc5da14f2b Mon Sep 17 00:00:00 2001 From: "Nathan T.A. Lewis" Date: Wed, 13 Sep 2023 14:48:44 -0600 Subject: [PATCH] fix: avoid TypeError if resp is undefined When `resp` is undefined, this error handling code will itself throw "TypeError: Cannot read properties of undefined (reading 'insertErrors')" Instead of throwing, we can use optional chaining to allow the error message to be handled as expected. --- src/rowQueue.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rowQueue.ts b/src/rowQueue.ts index 30c9710a..534921ce 100644 --- a/src/rowQueue.ts +++ b/src/rowQueue.ts @@ -168,7 +168,7 @@ export class RowQueue { json, }, (err, resp) => { - const partialFailures = (resp.insertErrors || []).map( + const partialFailures = (resp?.insertErrors || []).map( (insertError: GoogleErrorBody) => { return { errors: insertError.errors!.map(error => {