From 0e776448587897158c8285b7eacd40d4116e437c Mon Sep 17 00:00:00 2001 From: Sasha Kiselev Date: Thu, 16 Jan 2025 17:31:30 +0100 Subject: [PATCH] feat: allow json parse to be skipped --- .../src/strategies/http-abstract-call.strategy.ts | 1 + api-strategy/src/strategies/nest-local-call.strategy.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/api-strategy/src/strategies/http-abstract-call.strategy.ts b/api-strategy/src/strategies/http-abstract-call.strategy.ts index 691cf21..751f03b 100644 --- a/api-strategy/src/strategies/http-abstract-call.strategy.ts +++ b/api-strategy/src/strategies/http-abstract-call.strategy.ts @@ -4,6 +4,7 @@ import { IApiCallStrategy } from '../context-call.interface.js'; export interface IHttpCallStrategyOptions { headersWhitelist?: string[]; + shouldSkipJsonParse?: (body: string) => boolean; } /** diff --git a/api-strategy/src/strategies/nest-local-call.strategy.ts b/api-strategy/src/strategies/nest-local-call.strategy.ts index d2fefdb..fa2efe1 100644 --- a/api-strategy/src/strategies/nest-local-call.strategy.ts +++ b/api-strategy/src/strategies/nest-local-call.strategy.ts @@ -70,7 +70,14 @@ export class NestLocalCallStrategy extends HttpAbstractStrategy { let data; try { - data = result.json(); + if ( + this.options.shouldSkipJsonParse && + this.options.shouldSkipJsonParse(result.body) + ) { + data = result.body; + } else { + data = result.json(); + } } catch (_e) { //The content-type of the response is not application/json // if so, we use the body instead