-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
40 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
import { CommandInteraction } from 'discord.js' | ||
import { singleton } from 'tsyringe' | ||
import { parse } from 'stacktrace-parser' | ||
|
||
import { Logger } from '@services' | ||
import { BaseError } from '@utils/classes' | ||
|
||
|
||
@singleton() | ||
export class ErrorHandler { | ||
|
||
constructor( | ||
private logger: Logger | ||
) { | ||
// Catch all exeptions | ||
// Ccatch all exeptions | ||
process.on('uncaughtException', (error: Error, origin: string) => { | ||
// Stop if is unhandledRejection | ||
if(origin === "unhandledRejection") return; | ||
|
||
// If instance of BaseError, call `handle` method | ||
if(error instanceof BaseError) return error.handle(); | ||
// stop in case of unhandledRejection | ||
if (origin === "unhandledRejection") return | ||
|
||
// if instance of BaseError, call `handle` method | ||
if (error instanceof BaseError) return error.handle() | ||
|
||
// If the error is not a instance of BaseError | ||
const trace = parse(error.stack || "")?.[0]; | ||
if(trace) return this.logger.log("error", `Exception at : ${trace?.file}:${trace?.lineNumber}\n\t> ${error.message}`); | ||
// if the error is not a instance of BaseError | ||
const trace = parse(error.stack || "")?.[0] | ||
if (trace) return this.logger.log("error", `Exception at : ${trace?.file}:${trace?.lineNumber}\n\t> ${error.message}`) | ||
|
||
this.logger.log("error", "An error as occured in a unknow file\n\t> " + error.message); | ||
}); | ||
this.logger.log("error", "An error as occured in a unknow file\n\t> " + error.message) | ||
}) | ||
|
||
// Catch all Unhandled Rejection (promise) | ||
// catch all Unhandled Rejection (promise) | ||
process.on('unhandledRejection', (error: Error | any, promise: Promise<any>) => { | ||
// If instance of BaseError, call `handle` method | ||
if(error instanceof BaseError) return error.handle(); | ||
|
||
// If the error is not a instance of BaseError | ||
const trace = parse(error.stack || "")?.[0]; | ||
if(trace) return this.logger.log("error", `Unhandled rejection at ${trace?.file}:${trace?.lineNumber}\n\t> ${error.message}`); | ||
// if instance of BaseError, call `handle` method | ||
if(error instanceof BaseError) return error.handle() | ||
|
||
// if the error is not a instance of BaseError | ||
const trace = parse(error.stack || "")?.[0] | ||
if(trace) return this.logger.log("error", `Unhandled rejection at ${trace?.file}:${trace?.lineNumber}\n\t> ${error.message}`) | ||
|
||
this.logger.log("error", "An unhandled rejection as occured in a unknow file\n\t> " + error); | ||
}); | ||
this.logger.log("error", "An unhandled rejection as occured in a unknow file\n\t> " + error) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters