Skip to content

Commit e080121

Browse files
committed
error
1 parent 1cb423f commit e080121

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

index.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,16 @@ declare namespace Rollbar {
6666
context: TContext,
6767
callback: Callback<TResult>,
6868
) => void | Promise<TResult>;
69-
export type MaybeError = Error | undefined | null;
7069
export type Level = 'debug' | 'info' | 'warning' | 'error' | 'critical';
7170
export type Dictionary = Record<string, unknown>;
71+
export type MaybeError = Error | undefined | null;
7272
export type StringAttributes = Record<string, string>;
7373

74+
export interface ErrorWithContext extends Error {
75+
rollbarContext?: Record<string, any>;
76+
nested?: Error | null;
77+
}
78+
7479
/**
7580
* {@link https://docs.rollbar.com/docs/rollbarjs-configuration-reference#reference}
7681
*/

test/browser.rollbar.test-utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ declare global {
2323
}
2424
}
2525

26+
// Cause (for Error)
27+
// Error with cause is supported in +ES2022
28+
export interface Cause {
29+
cause?: Error;
30+
}
31+
2632
export const { fakeServer } = window.nise;
2733

2834
export const DUMMY_TRACE_ID = 'some-trace-id';

test/browser.transforms.test.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { expect } from 'chai';
33
import Rollbar from '../src/browser/rollbar.js';
44
import * as t from '../src/browser/transforms.js';
55

6+
import { Cause } from './browser.rollbar.test-utils.ts';
7+
68
function TestClientGen() {
79
const TestClient = function () {
810
this.notifier = {
@@ -438,7 +440,7 @@ describe('addBody', function () {
438440
describe('with nested error', function () {
439441
it('should create trace_chain', function (done) {
440442
const nestedErr = new Error('nested error');
441-
const err = new Error('test error') as Error & { nested?: Error };
443+
const err = new Error('test error') as Rollbar.ErrorWithContext;
442444
err.nested = nestedErr;
443445
const args = ['a message', err];
444446
const item = itemFromArgs(args);
@@ -458,14 +460,9 @@ describe('addBody', function () {
458460
});
459461
});
460462
it('should create add error context as custom data', function (done) {
461-
const nestedErr = new Error('nested error') as Error & {
462-
rollbarContext?: any;
463-
};
463+
const nestedErr = new Error('nested error') as Rollbar.ErrorWithContext;
464464
nestedErr.rollbarContext = { err1: 'nested context' };
465-
const err = new Error('test error') as Error & {
466-
rollbarContext?: any;
467-
nested?: Error;
468-
};
465+
const err = new Error('test error') as Rollbar.ErrorWithContext;
469466
err.rollbarContext = { err2: 'error context' };
470467
err.nested = nestedErr;
471468
const args = ['a message', err];
@@ -488,7 +485,7 @@ describe('addBody', function () {
488485

489486
it('should create trace_chain', function (done) {
490487
const causeErr = new Error('cause error');
491-
const err = new Error('test error') as Error & { cause?: Error };
488+
const err = new Error('test error') as Error & Cause;
492489
err.cause = causeErr;
493490
const args = ['a message', err];
494491
const item = itemFromArgs(args);
@@ -508,14 +505,9 @@ describe('addBody', function () {
508505
});
509506
});
510507
it('should create add error context as custom data', function (done) {
511-
const causeErr = new Error('cause error') as Error & {
512-
rollbarContext?: any;
513-
};
508+
const causeErr = new Error('cause error') as Rollbar.ErrorWithContext;
514509
causeErr.rollbarContext = { err1: 'cause context' };
515-
const err = new Error('test error') as Error & {
516-
rollbarContext?: any;
517-
cause?: Error;
518-
};
510+
const err = new Error('test error') as Rollbar.ErrorWithContext & Cause;
519511
err.cause = causeErr;
520512
err.rollbarContext = { err2: 'error context' };
521513
const args = ['a message', err];

0 commit comments

Comments
 (0)