From 33cdd37ba4db2ebc658bce4da13d5ff81a57bdf0 Mon Sep 17 00:00:00 2001 From: yarinvk Date: Wed, 24 Nov 2021 10:27:17 +0200 Subject: [PATCH] bugfix: when Idempotency key is undefined, axios fails sending post request --- src/api-client.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/api-client.ts b/src/api-client.ts index e94ac15b..3fb43cec 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -38,13 +38,17 @@ export class ApiClient { const token = this.authProvider.signJwt(path, body); const idempotencyKey = requestOptions?.idempotencyKey; + const headers: any = { + "X-API-Key": this.authProvider.getApiKey(), + "Authorization": `Bearer ${token}`, + }; + + if (idempotencyKey) { + headers["Idempotency-Key"] = idempotencyKey; + } return (await this.axiosInstance.post(path, body, { - headers: { - "X-API-Key": this.authProvider.getApiKey(), - "Authorization": `Bearer ${token}`, - "Idempotency-Key": idempotencyKey - }, + headers, timeout: this.options.timeoutInMs })).data; }