apps/api: check graphql response status & forward to response

This commit is contained in:
vchikalkin 2024-02-29 16:01:23 +03:00
parent eee91d5f2d
commit defc625324

View File

@ -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)