Provide better information in error reports by printing the stack trace and message of the original error instead of the Err wrapper
This commit is contained in:
parent
7afd5582eb
commit
01dd5eaf2a
|
@ -1,7 +0,0 @@
|
|||
<p>The following error occurred at {{ time }}:</p>
|
||||
|
||||
<p>
|
||||
Code: {{ code }} <br />
|
||||
Message: {{ message }} <br />
|
||||
Event ID: {{ eventId }}`
|
||||
</p>
|
|
@ -1,5 +0,0 @@
|
|||
The following error occurred at {{ time }}:
|
||||
|
||||
Code: {{ code }}
|
||||
Message: {{ message }}
|
||||
Event ID: {{ eventId }}`
|
|
@ -0,0 +1,5 @@
|
|||
<p>
|
||||
<pre>
|
||||
{{ message }}
|
||||
</pre>
|
||||
</p>
|
|
@ -0,0 +1 @@
|
|||
{{ message }}
|
|
@ -99,8 +99,10 @@ export class Err extends Error {
|
|||
}
|
||||
|
||||
toString() {
|
||||
return `Time: ${this.time.toISOString()}\nError Code: ${this.code}:\nError Message: ${
|
||||
this.message
|
||||
}\nStack Trace:\n${this.originalError ? this.originalError.stack : this.stack}`;
|
||||
return `Time: ${this.time.toISOString()}
|
||||
Error Code: ${this.code}
|
||||
Error Message: ${this.message}${this.originalError ? `\nOriginal Error Message: ${this.originalError.message}` : ""}
|
||||
Stack Trace:\n${this.originalError ? this.originalError.stack : this.stack}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,8 +60,8 @@ export class JoinOrgInviteCompletedMessage extends Message<{ orgName: string; op
|
|||
}
|
||||
}
|
||||
|
||||
export class ErrorMessage extends Message<{ code: string; message: string; time: string; eventId: string }> {
|
||||
template = "error";
|
||||
export class PlainMessage extends Message<{ message: string }> {
|
||||
template = "plain";
|
||||
|
||||
get title() {
|
||||
return "Padloc Error Notification";
|
||||
|
|
|
@ -44,7 +44,7 @@ import { Org, OrgID, OrgMember, OrgMemberStatus, OrgRole, ScimSettings } from ".
|
|||
import { Invite } from "./invite";
|
||||
import {
|
||||
ConfirmMembershipInviteMessage,
|
||||
ErrorMessage,
|
||||
PlainMessage,
|
||||
JoinOrgInviteAcceptedMessage,
|
||||
JoinOrgInviteCompletedMessage,
|
||||
JoinOrgInviteMessage,
|
||||
|
@ -2078,8 +2078,6 @@ export class Server {
|
|||
}
|
||||
|
||||
private async _handleError(error: Error, req: Request, res: Response, context: Context) {
|
||||
console.error(error);
|
||||
|
||||
const e =
|
||||
error instanceof Err
|
||||
? error
|
||||
|
@ -2096,6 +2094,8 @@ export class Server {
|
|||
};
|
||||
|
||||
if (e.report) {
|
||||
console.error(error);
|
||||
|
||||
const evt = this.log("error", context, {
|
||||
error: e.toRaw(),
|
||||
request: {
|
||||
|
@ -2108,13 +2108,12 @@ export class Server {
|
|||
try {
|
||||
await this.messenger.send(
|
||||
this.config.reportErrors,
|
||||
new ErrorMessage({
|
||||
time: e.time.toISOString(),
|
||||
code: e.code,
|
||||
message: `Endpoint: ${req.method}\nMessage: ${e.message}\nDevice Info:\n${
|
||||
new PlainMessage({
|
||||
message: `The following error occured at ${e.time.toISOString()}:\n\nEndpoint: ${
|
||||
req.method
|
||||
}\nDevice Info:\n${
|
||||
req.device && JSON.stringify(req.device?.toRaw(), null, 4)
|
||||
}\nStack Trace:\n${e.stack}`,
|
||||
eventId: evt.id,
|
||||
}\n${e.toString()}${evt?.id ? `Event ID: ${evt.id}` : ""}`,
|
||||
})
|
||||
);
|
||||
} catch (e) {}
|
||||
|
|
|
@ -11,7 +11,7 @@ import { AuthServer, AuthType } from "@padloc/core/src/auth";
|
|||
import { WebAuthnConfig, WebAuthnServer } from "./auth/webauthn";
|
||||
import { SMTPSender } from "./email/smtp";
|
||||
import { MongoDBStorage } from "./storage/mongodb";
|
||||
import { ConsoleMessenger, ErrorMessage } from "@padloc/core/src/messenger";
|
||||
import { ConsoleMessenger, PlainMessage } from "@padloc/core/src/messenger";
|
||||
import { FSAttachmentStorage, FSAttachmentStorageConfig } from "./attachments/fs";
|
||||
import {
|
||||
AttachmentStorageConfig,
|
||||
|
@ -302,7 +302,7 @@ async function init(config: PadlocConfig) {
|
|||
try {
|
||||
await emailSender.send(
|
||||
config.server.reportErrors,
|
||||
new ErrorMessage({
|
||||
new PlainMessage({
|
||||
code: ErrorCode.UNKNOWN_ERROR,
|
||||
message: `${err.message}\n${err.stack}`,
|
||||
time: new Date().toISOString(),
|
||||
|
|
Loading…
Reference in New Issue