getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.97k stars 1.57k forks source link

Issues type error stored in sentry server differs from error types in express app #3244

Closed memlucky71 closed 3 years ago

memlucky71 commented 3 years ago

Package + Version

Version:

5.5.0 (@sentry/node)

Description

I have recently migrated to use @sentry/node from ravan-node package. There is a problem while listing issues in sentry: While I have defined custom error classes with different custom error types, all issues title in sentry are captured as 'Error'. The output in

app.use(Sentry.Handlers.errorHandler({
  shouldHandleError(error) {
    console.log('error: ', JSON.stringify(error, '', 2))
    // Capture all 4XX and 5XX errors
    return error.status >= 400;
  },
}));

is:

error:  {
  "type": "NotFoundError",
  "status": 404,
  "code": 60,
  "details": {},
  "message": "default"
}

The reseponse from sentry server while listing issues:

{
...

culprit: "null.<anonymous>(app)"
level: "error"
logger: null
metadata: {function: "null.<anonymous>", type: "Error", value: "default",…}
status: "unresolved"
title: "Error: default"
type: "error"
}

Here is sample custom error I have:

export class NotFoundError extends Error {
  constructor(details, message) {
    super();
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, NotFoundError);
    }
    this.type = "NotFoundError";
    this.status = 404;
    this.code = 60;
    this.details = details || {};
    this.message = message || 'default';

    this.createErrorObject = () => {
      return {
        code: this.code,
        details: this.details
      }
    };
  }
}
github-actions[bot] commented 3 years ago

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀