Skip to content

Commit

Permalink
Fix instanceof bug
Browse files Browse the repository at this point in the history
  • Loading branch information
david1542 committed Jul 31, 2024
1 parent a74139c commit fcafd99
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 31 deletions.
3 changes: 0 additions & 3 deletions services/api/src/routers/oauth/atlassian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ router.get(

return res.send("App installed successfully");
} catch (error) {
if (error instanceof AppError) {
throw error;
}
if (error instanceof AxiosError) {
if (error.response) {
throw AppError({
Expand Down
3 changes: 0 additions & 3 deletions services/api/src/routers/oauth/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ router.get(

return res.send("App installed successfully");
} catch (error) {
if (error instanceof AppError) {
throw error;
}
if (error instanceof AxiosError) {
if (error.response) {
throw AppError({
Expand Down
3 changes: 0 additions & 3 deletions services/api/src/routers/oauth/notion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ router.get(

return res.send("App installed successfully");
} catch (error) {
if (error instanceof AppError) {
throw error;
}
if (error instanceof AxiosError) {
if (error.response) {
throw AppError({
Expand Down
3 changes: 0 additions & 3 deletions services/api/src/routers/oauth/pagerduty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ router.get(

return res.status(200).send("Successfully integrated PagerDuty!");
} catch (error) {
if (error instanceof AppError) {
throw error;
}
if (error instanceof AxiosError) {
if (error.response) {
throw AppError({
Expand Down
3 changes: 0 additions & 3 deletions services/api/src/routers/oauth/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ router.get(

return res.send("App installed successfully");
} catch (error) {
if (error instanceof AppError) {
throw error;
}
if (error instanceof AxiosError) {
if (error.response) {
throw AppError({
Expand Down
3 changes: 0 additions & 3 deletions services/api/src/services/oauth/atlassian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ export async function refreshToken(integrationId: string) {
});
} catch (error) {
console.log(error);
if (error instanceof AppError) {
throw error;
}
if (error instanceof AxiosError) {
if (error.response) {
throw AppError({
Expand Down
3 changes: 0 additions & 3 deletions services/api/src/services/oauth/pagerduty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export async function refreshToken(integrationId: string) {
});
} catch (error) {
console.log(error);
if (error instanceof AppError) {
throw error;
}
if (error instanceof AxiosError) {
if (error.response) {
throw AppError({
Expand Down
19 changes: 9 additions & 10 deletions services/api/src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ export const catchAsync = (
return (req: Request, res: Response, next: NextFunction) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleError = (error: any) => {
if (error instanceof AppError) {
next(error);
} else {
const newError = AppError({
message: error.message || "Internal error",
statusCode: 500,
});
newError.stack = error.stack;
next(newError);
}
const newError = AppError({
message: error.message || "Internal error",
statusCode: error.statusCode || 500,
internalCode: error.internalCode || "internal_error",
stack: error.stack,
context: error.context,
});
newError.stack = error.stack;
next(newError);
};

const isAsync = fn.constructor.name === "AsyncFunction";
Expand Down

0 comments on commit fcafd99

Please sign in to comment.