Skip to content

Commit

Permalink
chore: sentry & error handling improvements (#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoy authored Dec 19, 2023
2 parents 879aaa6 + ddda311 commit 0c5c519
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
1 change: 0 additions & 1 deletion packages/backend/src/routes/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ router.post(
);
} catch (e) {
e.status = 415;
Sentry.captureException(e);
throw e;
}

Expand Down
48 changes: 26 additions & 22 deletions packages/backend/src/services/data-export/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,33 @@ const recipeToSchema = async (

const imageUrl = recipe.images[0]?.location;
if (imageUrl && options?.includeImages) {
let buffer: Buffer;
if (process.env.NODE_ENV === "selfhost" && imageUrl.startsWith("/")) {
buffer = await fs.promises.readFile(imageUrl);
} else {
const response = await fetchURL(imageUrl);
buffer = await response.buffer();
try {
let buffer: Buffer;
if (process.env.NODE_ENV === "selfhost" && imageUrl.startsWith("/")) {
buffer = await fs.promises.readFile(imageUrl);
} else {
const response = await fetchURL(imageUrl);
buffer = await response.buffer();
}

schema.push({
columns: [
{
width: 100,
image: `data:image/jpeg;base64,${buffer.toString("base64")}`,
fit: [100, 100],
},
{
width: "auto",
stack: headerContent,
margin: [10, 10, 0, 0],
},
],
margin: [0, 0, 0, 10],
});
} catch (e) {
schema.push(...headerContent);
}

schema.push({
columns: [
{
width: 100,
image: `data:image/jpeg;base64,${buffer.toString("base64")}`,
fit: [100, 100],
},
{
width: "auto",
stack: headerContent,
margin: [10, 10, 0, 0],
},
],
margin: [0, 0, 0, 10],
});
} else {
schema.push(...headerContent);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ const checkChunkLoadError = (error: Error) => {
};

const checkSupressedError = (error: Error) => {
// These errors commonly come from Ionic and/or Webpack chunk loading. We don't want to send these to Sentry and consume our budget there.
const supressedErrorRegExp =
/(Loading chunk [\d]+ failed)|(Cstr is undefined)|(Cannot read property 'isProxied' of undefined)|(\.isProxied)|(\[object Undefined\])/;
/(Loading chunk [\d]+ failed)|(Cstr is undefined)|(Cannot read property 'isProxied' of undefined)|(Cannot read properties of undefined \(reading 'isProxied'\))|(\.isProxied)|(\[object Undefined\])/;

return supressedErrorRegExp.test(error.message);
};
Expand Down

0 comments on commit 0c5c519

Please sign in to comment.