diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..09b2bd0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +ARG NODE_VERSION=18.17.1 + +FROM node:${NODE_VERSION}-alpine + +WORKDIR /usr/src/app + +RUN apk update && apk add --no-cache nmap && \ + echo @edge https://dl-cdn.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \ + echo @edge https://dl-cdn.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories && \ + apk update && \ + apk add --no-cache \ + chromium \ + harfbuzz \ + "freetype>2.8" \ + ttf-freefont \ + nss + +ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true + +COPY . /usr/src/app + +RUN npm ci + +RUN npm run build + +EXPOSE 3000 + +CMD [ "node", "dist/src/main" ] \ No newline at end of file diff --git a/src/contract/contract.helper.ts b/src/contract/contract.helper.ts index 0580b3e..046932d 100644 --- a/src/contract/contract.helper.ts +++ b/src/contract/contract.helper.ts @@ -23,6 +23,8 @@ export class ContractHelper { const browser = await launch({ args: ['--no-sandbox'], + // comment the below line for running locally + executablePath: '/usr/bin/chromium', headless: true, }); const page = await browser.newPage(); diff --git a/src/interceptors/response.interceptor.ts b/src/interceptors/response.interceptor.ts index 409d883..48a8e93 100644 --- a/src/interceptors/response.interceptor.ts +++ b/src/interceptors/response.interceptor.ts @@ -45,13 +45,7 @@ export class ResponseInterceptor implements NestInterceptor { response.status(status).json({ status: false, statusCode: status, - message: - exception.getResponse() instanceof Object - ? Object(exception.getResponse()).reduce( - (acc, obj) => ({ ...Object(acc), ...Object(obj) }), - {}, - ) - : exception.getResponse(), + message: this.extractErrorMessages(exception), error: this.htttpCodeParser(status), }); } @@ -71,6 +65,22 @@ export class ResponseInterceptor implements NestInterceptor { }); } + private extractErrorMessages(exception: any) { + try { + return Object(exception.getResponse()).reduce( + (acc, obj) => ({ ...Object(acc), ...Object(obj) }), + {}, + ); + } catch (e) { + console.log( + '#Failed to restructure exception for this response: ', + exception.getResponse(), + " would return it's original response instead.", + ); + return exception.getResponse(); + } + } + private htttpCodeParser(statusCode: number) { switch (statusCode) { case 200: