Skip to content

Commit 55ec10e

Browse files
chore(pm-app): unify error usage (#88)
1 parent 4ac9b02 commit 55ec10e

File tree

10 files changed

+31
-32
lines changed

10 files changed

+31
-32
lines changed

pm-app/app/routes/dashboard/projects/$projectId/delete.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export const action: ActionFunction = async ({ request, params }) => {
1212
if (projectId) {
1313
try {
1414
await deleteProject(projectId);
15-
} catch (e) {
16-
console.error(e);
15+
} catch (error: unknown) {
16+
console.error(error);
1717
}
1818
}
1919
return redirect("/dashboard");

pm-app/app/routes/dashboard/todos/$todoId/delete.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const action: ActionFunction = async ({ request, params }) => {
2222
try {
2323
actionData = { todo: await deleteTodo(todoId) };
2424
return json(actionData);
25-
} catch (e) {
25+
} catch {
2626
actionData = { todo: null };
2727
return json(actionData, 400);
2828
}

pm-app/app/routes/dashboard/todos/$todoId/edit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const action: ActionFunction = async ({ request, context, params }) => {
5050
const todo = await updateTodo(todoId, todoUpdates);
5151
actionData = { todo };
5252
return json(actionData, 200);
53-
} catch (e) {
53+
} catch {
5454
actionData = { todo: null };
5555
return json(actionData, 400);
5656
}

pm-app/app/routes/dashboard/todos/$todoId/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ export const action: ActionFunction = async ({ request, context, params }) => {
4747
});
4848
actionData = { todo };
4949
return json(actionData, 200);
50-
} catch (e) {
51-
// console.error(e);
50+
} catch {
5251
actionData = { todo: null };
5352
return json(actionData, 400);
5453
}

pm-app/app/routes/dashboard/todos/$todoId/set.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const action: ActionFunction = async ({ request, params }) => {
2727
});
2828
actionData = { todo };
2929
return json(actionData, 200);
30-
} catch (e) {
30+
} catch {
3131
actionData = { todo: null };
3232
return json(actionData, 400);
3333
}

pm-app/app/routes/dashboard/todos/new.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const action: ActionFunction = async ({ request, params }) => {
5050
const todo = await createTodo(todoData);
5151
actionData = { todo };
5252
return json(actionData, 200);
53-
} catch (e) {
53+
} catch {
5454
actionData = { todo: null };
5555
return json(actionData, 400);
5656
}

pm-app/app/routes/register.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export const action: ActionFunction = async ({ request }) => {
8383
} else {
8484
try {
8585
validateEmail(email);
86-
} catch (e) {
87-
fieldErrors.email = (e as Error).message;
86+
} catch (error: unknown) {
87+
fieldErrors.email = (error as Error).message;
8888
}
8989
}
9090

@@ -93,8 +93,8 @@ export const action: ActionFunction = async ({ request }) => {
9393
} else {
9494
try {
9595
validatePassword(password);
96-
} catch (e) {
97-
fieldErrors.password = (e as Error).message;
96+
} catch (error: unknown) {
97+
fieldErrors.password = (error as Error).message;
9898
}
9999
}
100100

pm-app/app/routes/sign-in.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ export const action: ActionFunction = async ({ request }) => {
6060
} else {
6161
try {
6262
validateEmail(email);
63-
} catch (e) {
64-
if (e instanceof Error) {
65-
fieldErrors.email = e.message;
66-
} else if (typeof e === "string") {
67-
fieldErrors.email = e;
63+
} catch (error: unknown) {
64+
if (error instanceof Error) {
65+
fieldErrors.email = error.message;
66+
} else if (typeof error === "string") {
67+
fieldErrors.email = error;
6868
} else {
6969
fieldErrors.email = "There was an error with this field";
7070
}
@@ -76,11 +76,11 @@ export const action: ActionFunction = async ({ request }) => {
7676
} else {
7777
try {
7878
validatePassword(password);
79-
} catch (e) {
80-
if (e instanceof Error) {
81-
fieldErrors.password = e.message;
82-
} else if (typeof e === "string") {
83-
fieldErrors.password = e;
79+
} catch (error: unknown) {
80+
if (error instanceof Error) {
81+
fieldErrors.password = error.message;
82+
} else if (typeof error === "string") {
83+
fieldErrors.password = error;
8484
} else {
8585
fieldErrors.password = "There was an error with this field";
8686
}
@@ -95,12 +95,12 @@ export const action: ActionFunction = async ({ request }) => {
9595
let user: User | null;
9696
try {
9797
user = await login(email, password);
98-
} catch (e) {
98+
} catch (error: unknown) {
9999
let formError: string;
100-
if (e instanceof Error) {
101-
formError = e.message;
102-
} else if (typeof e === "string") {
103-
formError = e;
100+
if (error instanceof Error) {
101+
formError = error.message;
102+
} else if (typeof error === "string") {
103+
formError = error;
104104
} else {
105105
formError = "There was an error logging in. Please try again later.";
106106
}

pm-app/app/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export function getClientSafeEnvVariable<
3535
);
3636
}
3737
return ENV[key];
38-
} catch (err) {
38+
} catch (error) {
3939
console.error(
4040
"There was an error parsing window.ENV. See https://remix.run/guides/envvars#browser-environment-variables"
4141
);
42-
throw err;
42+
throw error;
4343
}
4444
} else {
4545
return process.env[key];

pm-app/app/utils/sanitizer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class Sanitizer {
2424
if (typeof arg === "number") {
2525
flo = parseFloat(flo.toFixed(arg));
2626
}
27-
} catch (e) {
27+
} catch {
2828
return null;
2929
}
3030
return flo;
@@ -33,7 +33,7 @@ export class Sanitizer {
3333
static int(value: any) {
3434
try {
3535
return parseInt(value);
36-
} catch (e) {
36+
} catch {
3737
return null;
3838
}
3939
}
@@ -114,7 +114,7 @@ export class Sanitizer {
114114
return JSON.parse(JSON.stringify(value));
115115
}
116116
return null;
117-
} catch (e) {
117+
} catch {
118118
return null;
119119
}
120120
}

0 commit comments

Comments
 (0)