From defc625324364016a4f43db849338fc60188d41a Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 29 Feb 2024 16:01:23 +0300 Subject: [PATCH] apps/api: check graphql response status & forward to response --- apps/api/src/proxy/proxy.controller.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/api/src/proxy/proxy.controller.ts b/apps/api/src/proxy/proxy.controller.ts index 956c576..4e04bec 100644 --- a/apps/api/src/proxy/proxy.controller.ts +++ b/apps/api/src/proxy/proxy.controller.ts @@ -1,7 +1,15 @@ import { queryTTL } from './lib/config'; import type { GQLRequest } from './types'; import { CACHE_MANAGER } from '@nestjs/cache-manager'; -import { All, Controller, Inject, Req, Res } from '@nestjs/common'; +import { + All, + Controller, + HttpException, + HttpStatus, + Inject, + Req, + Res, +} from '@nestjs/common'; import type { Cache } from 'cache-manager'; import { FastifyReply, FastifyRequest } from 'fastify'; import { env } from 'src/config/env'; @@ -34,6 +42,12 @@ export class ProxyController { method: req.method, }); + if (!response.ok) + throw new HttpException( + response.statusText, + response.status || HttpStatus.INTERNAL_SERVER_ERROR, + ); + const data = await response.json(); const ttl = queryTTL[operationName]; if (data && ttl !== false)