Skip to content

Commit 375d3a3

Browse files
committed
fix: merge send stack with superagent error stack
1 parent 7e6be97 commit 375d3a3

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/CoreError.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ class CoreError extends Boom {
2323

2424
super(message ? message : undefined, options);
2525

26-
if (typeof message === 'string' || !this.isServer) {
26+
if (
27+
(typeof message === 'string' || !this.isServer) &&
28+
ctr.name !== CoreError.name
29+
) {
2730
Error.captureStackTrace(this, ctr);
2831
} else {
2932
this.message = 'Internal error';

lib/Request.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ class Request {
6565
* @throws {CoreError} Returns error or max authenticated request limit reached
6666
*/
6767
async send(method, path, opts) {
68+
let trace = {};
69+
Error.captureStackTrace(trace, this.send);
70+
trace.stack = trace.stack
71+
.split('\n')
72+
.splice(1)
73+
.join('\n');
74+
6875
opts = Object.assign(
6976
{
7077
headers: {},
@@ -143,6 +150,8 @@ class Request {
143150

144151
return body;
145152
} catch (error) {
153+
error.stack = [error.stack, trace.stack].join('\n');
154+
146155
if (
147156
this.isCacheEnabled &&
148157
opts.cache &&
@@ -208,7 +217,7 @@ class Request {
208217
? error.response.text
209218
: error instanceof CoreError && (error.isInternal || error.isCache)
210219
? error.typeof.name
211-
: error.stack;
220+
: `${error.name}: ${error.message}`;
212221

213222
if (!opts.mute) {
214223
this.log(

0 commit comments

Comments
 (0)