Skip to content

Commit

Permalink
feat: add error tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
arsaizdihar committed Jun 14, 2024
1 parent 3fdf3db commit 3f4267a
Show file tree
Hide file tree
Showing 12 changed files with 342 additions and 424 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ R2_PUBLIC_URL=https://your_r2_public_url.com
R2_BUCKET_NAME=your_r2_bucket_name
JWT_SECRET=your_jwt_secret
TOKEN_EXPIRATION=2592000
LOGIN_BYPASS_KEY=your_login_bypass_key
LOGIN_BYPASS_KEY=your_login_bypass_key
SENTRY_DSN=
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@aws-sdk/client-s3": "^3.556.0",
"@aws-sdk/s3-request-presigner": "^3.563.0",
"@hono/node-server": "^1.8.2",
"@hono/sentry": "^1.1.0",
"@hono/swagger-ui": "^0.2.1",
"@hono/zod-openapi": "^0.9.9",
"@paralleldrive/cuid2": "^2.2.2",
Expand Down
76 changes: 76 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/configs/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const EnvSchema = z.object({
LOGIN_BYPASS_KEY: z.string().default('default-bypass-key'),
GOOGLE_CALENDAR_SECRET_PATH: z.string().default('google_credentials.json'),
GOOGLE_CALENDAR_ID: z.string().default('primary'),
SENTRY_DSN: z.string().url().optional(),
});

const result = EnvSchema.safeParse(process.env);
Expand Down
16 changes: 8 additions & 8 deletions src/controllers/calendar.controller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { GaxiosError } from 'gaxios';
import { calendar_v3, google } from 'googleapis';
import { env } from '~/configs/env.config';
import { googleAuth } from '~/lib/googleapi';
import {
deleteCalendarEventRoute,
getCalendarEventByIdRoute,
Expand All @@ -6,10 +10,6 @@ import {
updateCalendarEventRoute,
} from '~/routes/calendar.route';
import { createAuthRouter } from './router-factory';
import { google, calendar_v3 } from 'googleapis';
import { GaxiosError } from 'gaxios';
import { googleAuth } from '~/lib/googleapi';
import { env } from '~/configs/env.config';

export const calendarRouter = createAuthRouter();

Expand Down Expand Up @@ -44,7 +44,7 @@ calendarRouter.openapi(postCalendarEventRoute, async (c) => {
if (error instanceof GaxiosError) {
return c.json({ error: error.message }, 400);
}
return c.json({ error: 'Something went wrong' }, 500);
throw error;
}
});

Expand All @@ -69,7 +69,7 @@ calendarRouter.openapi(getCalendarEventRoute, async (c) => {
if (error instanceof GaxiosError) {
return c.json({ error: error.message }, 400);
}
return c.json({ error: 'Something went wrong' }, 500);
throw error;
}
});

Expand All @@ -88,7 +88,7 @@ calendarRouter.openapi(getCalendarEventByIdRoute, async (c) => {
if (error instanceof GaxiosError) {
return c.json({ error: error.message }, 400);
}
return c.json({ error: 'Something went wrong' }, 500);
throw error;
}
});

Expand Down Expand Up @@ -149,6 +149,6 @@ calendarRouter.openapi(deleteCalendarEventRoute, async (c) => {
if (error instanceof GaxiosError) {
return c.json({ error: error.message }, 400);
}
return c.json({ error: 'Something went wrong' }, 500);
throw error;
}
});
21 changes: 6 additions & 15 deletions src/controllers/category.controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { db } from '~/db/drizzle';
import { getCategoryById, getCategoryList } from '~/repositories/category.repo';
import {
getCategoryByIdRoute,
getListCategoryRoute,
} from '~/routes/category.route';
import { createAuthRouter } from './router-factory';
import { db } from '~/db/drizzle';
import { getCategoryById, getCategoryList } from '~/repositories/category.repo';

export const categoryRouter = createAuthRouter();

Expand All @@ -14,17 +14,8 @@ categoryRouter.openapi(getListCategoryRoute, async (c) => {
});

categoryRouter.openapi(getCategoryByIdRoute, async (c) => {
try {
const { categoryId } = c.req.valid('param');
const category = await getCategoryById(db, categoryId);
if (!category) return c.json({ error: 'Category not found' }, 404);
return c.json(category, 200);
} catch (err) {
return c.json(
{
error: 'Something went wrong',
},
400,
);
}
const { categoryId } = c.req.valid('param');
const category = await getCategoryById(db, categoryId);
if (!category) return c.json({ error: 'Category not found' }, 404);
return c.json(category, 200);
});
2 changes: 1 addition & 1 deletion src/controllers/comment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ commentRouter.openapi(postCommentRoute, async (c) => {
} catch (err) {
if (err instanceof PostgresError)
return c.json({ error: err.message }, 400);
return c.json(err, 400);
throw err;
}
});

Expand Down
Loading

0 comments on commit 3f4267a

Please sign in to comment.