Skip to content

Commit

Permalink
fix(printer): increase timeout to 15s
Browse files Browse the repository at this point in the history
  • Loading branch information
AmruthPillai committed Nov 14, 2023
1 parent 36b1930 commit 457aed5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 34 deletions.
17 changes: 10 additions & 7 deletions apps/client/src/libs/axios.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { t } from "@lingui/macro";
import { deepSearchAndParseDates } from "@reactive-resume/utils";
import { deepSearchAndParseDates, ErrorMessage } from "@reactive-resume/utils";
import _axios from "axios";
import createAuthRefreshInterceptor from "axios-auth-refresh";
import { redirect } from "react-router-dom";
Expand All @@ -25,13 +25,16 @@ axios.interceptors.response.use(
return { ...response, data: transformedResponse };
},
(error) => {
const message = error.response?.data.message || error.message;
const message = error.response?.data.message as ErrorMessage;
const description = translateError(message);

toast({
variant: "error",
title: t`Oops, the server returned an error.`,
description: translateError(message),
});
if (description) {
toast({
variant: "error",
title: t`Oops, the server returned an error.`,
description,
});
}

return Promise.reject(error);
},
Expand Down
2 changes: 1 addition & 1 deletion apps/client/src/services/errors/translate-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ export const translateError = (error: ErrorMessage) => {
return t`Something went wrong while processing your request. Please try again later or raise an issue on GitHub.`;

default:
return error;
return null;
}
};
4 changes: 2 additions & 2 deletions apps/server/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const configSchema = z.object({
PORT: z.coerce.number().default(3000),

// Client Port & URL (only for development environments)
__DEV__CLIENT_PORT: z.coerce.number().default(5173),
__DEV__CLIENT_URL: z.string().url().default("http://localhost:5173"),
__DEV__CLIENT_PORT: z.coerce.number().optional(),
__DEV__CLIENT_URL: z.string().url().optional(),

// URLs
PUBLIC_URL: z.string().url(),
Expand Down
6 changes: 2 additions & 4 deletions apps/server/src/printer/printer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Config } from "../config/schema";
import { StorageService } from "../storage/storage.service";
import { UtilsService } from "../utils/utils.service";

const PRINTER_TIMEOUT = 10000; // 10 seconds
const PRINTER_TIMEOUT = 15000; // 15 seconds

@Injectable()
export class PrinterService {
Expand Down Expand Up @@ -76,9 +76,7 @@ export class PrinterService {
async printPreview(resume: ResumeDto) {
return this.utils.getCachedOrSet(
`user:${resume.userId}:storage:previews:${resume.id}`,
async () => {
return withTimeout(this.generatePreview(resume), PRINTER_TIMEOUT);
},
async () => withTimeout(this.generatePreview(resume), PRINTER_TIMEOUT),
);
}

Expand Down
26 changes: 12 additions & 14 deletions apps/server/src/translation/translation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export class TranslationService {
) {}

async fetchLanguages() {
const isDevelopment = this.configService.get("NODE_ENV") === "development";

try {
const projectId = this.configService.getOrThrow("CROWDIN_PROJECT_ID");
const accessToken = this.configService.getOrThrow("CROWDIN_ACCESS_TOKEN");
Expand All @@ -34,6 +32,7 @@ export class TranslationService {
);
const { data } = response.data as CrowdinResponse;

// Add English Locale
data.push({
data: {
language: {
Expand All @@ -46,19 +45,18 @@ export class TranslationService {
},
});

if (isDevelopment) {
data.push({
data: {
language: {
id: "zu-ZA",
locale: "zu-ZA",
editorCode: "zuza",
name: "Psuedo Locale",
},
translationProgress: 100,
// Add Pseudo Locale
data.push({
data: {
language: {
id: "zu-ZA",
locale: "zu-ZA",
editorCode: "zuza",
name: "Psuedo Locale",
},
});
}
translationProgress: 100,
},
});

return data.map(({ data }) => {
return {
Expand Down
7 changes: 1 addition & 6 deletions libs/utils/src/namespaces/promise.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
export const delay = (time: number) => new Promise((resolve) => setTimeout(resolve, time));

export const withTimeout = async <T>(promise: Promise<T>, time: number): Promise<T> => {
const timeout = new Promise((_, reject) =>
setTimeout(() => {
reject(new Error(`Operation timed out after ${time} ms.`));
}, time),
);

const timeout = new Promise((_, reject) => setTimeout(() => reject, time));
return Promise.race([promise, timeout]) as T;
};

0 comments on commit 457aed5

Please sign in to comment.