mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Let's not overwrite the error message when we're fixing the stack.
This commit is contained in:
parent
d9c30f586a
commit
a88a494f7a
@ -226,7 +226,9 @@ function patchMatrixClientForConciseExceptions() {
|
|||||||
}
|
}
|
||||||
let originalRequestFn = getRequestFn();
|
let originalRequestFn = getRequestFn();
|
||||||
setRequestFn((params, cb) => {
|
setRequestFn((params, cb) => {
|
||||||
let stack = new Error().stack;
|
// Store an error early, to maintain *some* semblance of stack.
|
||||||
|
// We'll only throw the error if there is one.
|
||||||
|
let error = new Error("STACK CAPTURE");
|
||||||
originalRequestFn(params, function conciseExceptionRequestFn(err, response, resBody) {
|
originalRequestFn(params, function conciseExceptionRequestFn(err, response, resBody) {
|
||||||
if (!err && (response?.statusCode < 200 || response?.statusCode >= 300)) {
|
if (!err && (response?.statusCode < 200 || response?.statusCode >= 300)) {
|
||||||
// Normally, converting HTTP Errors into rejections is done by the caller
|
// Normally, converting HTTP Errors into rejections is done by the caller
|
||||||
@ -280,8 +282,8 @@ function patchMatrixClientForConciseExceptions() {
|
|||||||
if ("body" in err) {
|
if ("body" in err) {
|
||||||
body = (err as any).body;
|
body = (err as any).body;
|
||||||
}
|
}
|
||||||
let error = new Error(`Error during MatrixClient request ${method} ${path}: ${err.statusCode} ${err.statusMessage} -- ${body}`);
|
let message = `Error during MatrixClient request ${method} ${path}: ${err.statusCode} ${err.statusMessage} -- ${body}`;
|
||||||
error.stack = stack;
|
error.message = message;
|
||||||
if (body) {
|
if (body) {
|
||||||
// Calling code may use `body` to check for errors, so let's
|
// Calling code may use `body` to check for errors, so let's
|
||||||
// make sure that we're providing it.
|
// make sure that we're providing it.
|
||||||
@ -299,6 +301,7 @@ function patchMatrixClientForConciseExceptions() {
|
|||||||
// Calling code may use `statusCode` to check for errors, so let's
|
// Calling code may use `statusCode` to check for errors, so let's
|
||||||
// make sure that we're providing it.
|
// make sure that we're providing it.
|
||||||
if ("statusCode" in err) {
|
if ("statusCode" in err) {
|
||||||
|
// Define the property but don't make it visible during logging.
|
||||||
Object.defineProperty(error, "statusCode", {
|
Object.defineProperty(error, "statusCode", {
|
||||||
value: err.statusCode,
|
value: err.statusCode,
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user