-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: #197 Refactor to use Promises internally #200
Conversation
Co-authored-by: Sumitra Manga <[email protected]>
const errorMessage = `Error is too large to send to Raygun (${messageSize}kb)\nStart of error: ${startOfMessage}`; | ||
console.error(`[Raygun4Node] ${errorMessage}`); | ||
throw Error(errorMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throw error upwards if the reported error message is too big, otherwise users will not notice.
See issue #140
.then((response) => { | ||
const durationInMs = stopTimer(); | ||
debug( | ||
`[raygun.ts] Successfully sent message (duration=${durationInMs}ms)`, | ||
); | ||
return response; | ||
}) | ||
.catch((error) => { | ||
const durationInMs = stopTimer(); | ||
debug( | ||
`[raygun.ts] Error sending message (duration=${durationInMs}ms): ${error}`, | ||
); | ||
return error; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap the transport.send
call with a then/catch
so we can log our own error/success messages, but still send the results back to the end user.
This is what was done in wrappedCallback
.
sendWithCallback( | ||
exception: Error | string, | ||
customData?: CustomData, | ||
callback?: Callback<IncomingMessage>, | ||
request?: RequestParams, | ||
tags?: Tag[], | ||
) { | ||
// call async send but redirect response to provided legacy callback | ||
this.send(exception, customData, request, tags) | ||
.then((response) => { | ||
if (callback) { | ||
callVariadicCallback(callback, null, response); | ||
} | ||
}) | ||
.catch((error) => { | ||
if (callback) { | ||
callVariadicCallback(callback, error, null); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Legacy send with a callback, wraps the new async send call.
IMO should be removed in the future.
test("send with expressHandler custom data", function (t) { | ||
t.plan(1); | ||
let client = new Raygun.Client().init({ | ||
apiKey: API_KEY, | ||
}); | ||
|
||
client.expressCustomData = function () { | ||
return { test: "data" }; | ||
}; | ||
client._send = client.send; | ||
client.send = (err, data, params, tags) => { | ||
client.send = client._send; | ||
t.equal(data.test, "data"); | ||
t.end(); | ||
return Promise.resolve(null); | ||
}; | ||
client.expressHandler(new Error(), {}, {}, function () {}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test is moved to raygun_async_send
because express handler now uses async send
internally.
test/raygun_send_test.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test file should be removed when we remove sendWithCallback
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a quick glance, this LGTM!
thanks @sumitramanga ! I will wait to merge until |
refactor: #197 Refactor to use Promises internally
Description 📝
raygun.transport.ts
to use Promises instead of callbaks #197raygun.transport.ts
should be ignored #198Type of change
Updates
SendOptions
internal type.raygun.transport.ts
to return a Promise instead of using a callback.raygun.sync.worker.ts
to the changes inraygun.transport.ts
.raygun.batch.ts
to the changes inraygun.transport.ts
.send()
method to implement logic directly instead of depending on legacysendWithCallback
.sendWithCallback()
to use newsend()
method internally.Test plan 🧪
Author to check 👓
Reviewer to check ✔️