Skip to content

Commit

Permalink
Merge pull request #41 from richard483/feature/run-week-1
Browse files Browse the repository at this point in the history
updated dockerfile & response interceptor
  • Loading branch information
richard483 authored Dec 8, 2023
2 parents b8ee73f + d7777e9 commit 53d7b59
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
2 changes: 2 additions & 0 deletions src/contract/contract.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
24 changes: 17 additions & 7 deletions src/interceptors/response.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
}
Expand All @@ -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:
Expand Down

0 comments on commit 53d7b59

Please sign in to comment.