Skip to content

Commit

Permalink
prettier run
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelbeltran committed May 2, 2024
1 parent 94714b6 commit cdfac68
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 63 deletions.
50 changes: 27 additions & 23 deletions lib/raygun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,26 +191,27 @@ class Raygun {
* @param customData to attach to the error report
* @param request custom RequestParams
* @param tags to attach to the error report
* @return IncomingMessage if message was delivered, null if stored, rejected with Error if failed.
*/
async send(
exception: Error | string,
customData?: CustomData,
request?: RequestParams,
tags?: Tag[],
exception: Error | string,
customData?: CustomData,
request?: RequestParams,
tags?: Tag[],
): Promise<IncomingMessage | null> {
return new Promise((resolve, reject) => {
this.sendWithCallback(
exception,
customData,
function (err, message) {
if (err != null) {
reject(err);
} else {
resolve(message);
}
},
request,
tags,
exception,
customData,
function (err, message) {
if (err != null) {
reject(err);
} else {
resolve(message);
}
},
request,
tags,
);
});
}
Expand Down Expand Up @@ -242,11 +243,10 @@ class Raygun {
const sendOptions = sendOptionsResult.options;

if (this._isOffline) {
let saveCallback = callback ? (err: Error | null) => callVariadicCallback(callback, err, null) : emptyCallback;
this.offlineStorage().save(
JSON.stringify(message),
saveCallback,
);
let saveCallback = callback
? (err: Error | null) => callVariadicCallback(callback, err, null)
: emptyCallback;
this.offlineStorage().save(JSON.stringify(message), saveCallback);
} else {
this.transport().send(sendOptions);
}
Expand Down Expand Up @@ -316,9 +316,13 @@ class Raygun {
body: req.body,
};

this.sendWithCallback(err, customData || {}, function () {}, requestParams, [
"UnhandledException",
]);
this.sendWithCallback(
err,
customData || {},
function () {},
requestParams,
["UnhandledException"],
);
next(err);
}

Expand Down
93 changes: 53 additions & 40 deletions test/raygun_async_send_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ test("async send basic", {}, function (t) {
let client = new Raygun.Client().init({
apiKey: API_KEY,
});
client.send(new Error()).then((response) => {
t.equal(response.statusCode, 202);
t.end();
}).catch((err) => {
t.fail(err);
});
client
.send(new Error())
.then((response) => {
t.equal(response.statusCode, 202);
t.end();
})
.catch((err) => {
t.fail(err);
});
});

test("async send complex", {}, function (t) {
Expand All @@ -49,12 +52,15 @@ test("async send complex", {}, function (t) {
.setUser("[email protected]")
.setVersion("1.0.0.0");

client.send(new Error()).then((response) => {
t.equal(response.statusCode, 202);
t.end();
}).catch((err) => {
t.fail(err);
});
client
.send(new Error())
.then((response) => {
t.equal(response.statusCode, 202);
t.end();
})
.catch((err) => {
t.fail(err);
});
});

test("async send with inner error", {}, function (t) {
Expand All @@ -76,12 +82,15 @@ test("async send with inner error", {}, function (t) {
let client = new Raygun.Client().init({
apiKey: API_KEY,
});
client.send(new Error()).then((response) => {
t.equal(response.statusCode, 202);
t.end();
}).catch((err) => {
t.fail(err);
});
client
.send(new Error())
.then((response) => {
t.equal(response.statusCode, 202);
t.end();
})
.catch((err) => {
t.fail(err);
});
});

test("async send with verror", {}, function (t) {
Expand All @@ -101,12 +110,15 @@ test("async send with verror", {}, function (t) {
let client = new Raygun.Client().init({
apiKey: API_KEY,
});
client.send(error).then((response) => {
t.equal(response.statusCode, 202);
t.end();
}).catch((err) => {
t.fail(err);
});
client
.send(error)
.then((response) => {
t.equal(response.statusCode, 202);
t.end();
})
.catch((err) => {
t.fail(err);
});
});

test("async send with OnBeforeSend", {}, function (t) {
Expand All @@ -128,12 +140,15 @@ test("async send with OnBeforeSend", {}, function (t) {
return payload;
});

client.send(new Error()).then((response) => {
t.equal(onBeforeSendCalled, true);
t.end();
}).catch((err) => {
t.fail(err);
});
client
.send(new Error())
.then((response) => {
t.equal(onBeforeSendCalled, true);
t.end();
})
.catch((err) => {
t.fail(err);
});
});

test("check that tags get passed through in async send", {}, function (t) {
Expand Down Expand Up @@ -161,14 +176,12 @@ test("check that tags get merged", {}, function (t) {
return payload;
});

client.send(
new Error(),
{},
null,
["Tag2"],
).then((message) => {
t.end();
}).catch((err) => {
t.fail(err);
});
client
.send(new Error(), {}, null, ["Tag2"])
.then((message) => {
t.end();
})
.catch((err) => {
t.fail(err);
});
});

0 comments on commit cdfac68

Please sign in to comment.