1
0
mirror of https://github.com/eleith/emailjs.git synced 2024-07-01 10:50:57 +00:00
emailjs/smtp/error.ts

46 lines
761 B
TypeScript
Raw Normal View History

2020-05-01 16:25:32 +00:00
/**
* @readonly
* @enum
*/
export const SMTPErrorStates = {
COULDNOTCONNECT: 1,
BADRESPONSE: 2,
AUTHFAILED: 3,
TIMEDOUT: 4,
ERROR: 5,
NOCONNECTION: 6,
AUTHNOTSUPPORTED: 7,
CONNECTIONCLOSED: 8,
CONNECTIONENDED: 9,
CONNECTIONAUTH: 10,
} as const;
2020-04-23 04:26:49 +00:00
class SMTPError extends Error {
public code: number | null = null;
2020-05-24 14:47:49 +00:00
public smtp: unknown = null;
public previous: Error | null = null;
2020-04-26 16:20:56 +00:00
constructor(message: string) {
super(message);
}
}
2020-04-23 04:26:49 +00:00
export function makeSMTPError(
message: string,
code: number,
2020-05-01 16:25:32 +00:00
error?: Error | null,
2020-05-24 14:47:49 +00:00
smtp?: unknown
2020-04-23 04:26:49 +00:00
) {
2020-04-26 16:20:56 +00:00
const msg = error?.message ? `${message} (${error.message})` : message;
const err = new SMTPError(msg);
err.code = code;
err.smtp = smtp;
if (error) {
err.previous = error;
}
return err;
}