Skip to content

Commit

Permalink
Add sentry to api (#460)
Browse files Browse the repository at this point in the history
* add sentry to API

* better capture errors instead of failing

* add @sentry/tracing to package mgr

* fix file access error
  • Loading branch information
davidkircos authored and HactarCE committed May 8, 2023
1 parent 1756037 commit 5defc51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 11 additions & 3 deletions quadratic-api/src/helpers/get_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ import { PrismaClient, QUser } from '@prisma/client';
const prisma = new PrismaClient();

export const get_file = async (user: QUser, uuid: string) => {
// Get the file from the database, only if it exists and the user owns it
return await prisma.qFile.findFirst({
// Get the file from the database by uuid
const file = await prisma.qFile.findFirst({
where: {
qUserId: user.id, // important to prevent users from getting access to files they don't own
uuid,
},
});

if (!file) return null;

// only return the file if the user is the owner
if (user.id === file.qUserId) {
return file;
}

throw new Error('File owner does not match user request');
};
8 changes: 0 additions & 8 deletions quadratic-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ if (SENTRY_DSN) {

// The error handler must be before any other error middleware and after all controllers
app.use(Sentry.Handlers.errorHandler());

// Optional fallthrough error handler
app.use((err: any, req: Request, res: any, next: NextFunction) => {
// The error id is attached to `res.sentry` to be returned
// and optionally displayed to the user for support.
res.statusCode = 500;
res.end(res.sentry + '\n');
});
}

// Error-logging middleware
Expand Down

0 comments on commit 5defc51

Please sign in to comment.