Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13 feature send handled errors to discord #42

Merged
merged 6 commits into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"ora": "^5.4.1",
"pidusage": "^3.0.0",
"reflect-metadata": "^0.1.13",
"rentry-pastebin": "^1.2.3",
"rxeta": "^1.1.2",
"saveqlite": "^1.1.2",
"socket.io-client": "^4.5.1",
Expand Down
6 changes: 6 additions & 0 deletions src/config/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@ export const logsConfig: LogsConfigType = {
file: true,
console: true,
channel: null
},

error: {
file: true,
console: true,
channel: "999745206809272471"
}
}
32 changes: 32 additions & 0 deletions src/entities/Pastebin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Entity, PrimaryKey, Property, EntityRepositoryType } from '@mikro-orm/core'
import { EntityRepository } from '@mikro-orm/sqlite'

// ===========================================
// ================= Entity ==================
// ===========================================

@Entity({ customRepository: () => PastebinRepository })
export class Pastebin {

[EntityRepositoryType]?: PastebinRepository

@PrimaryKey({ autoincrement: false })
id: string

@Property()
editCode: string

@Property()
lifetime: number = -1

@Property()
createdAt: Date = new Date()
}

// ===========================================
// =========== Custom Repository =============
// ===========================================

export class PastebinRepository extends EntityRepository<Pastebin> {

}
3 changes: 2 additions & 1 deletion src/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from './User'
export * from './Guild'
export { Data } from './Data'
export * from './Stat'
export * from './Image'
export * from './Image'
export * from './Pastebin'
36 changes: 9 additions & 27 deletions src/services/ErrorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Client } from 'discordx'
import { singleton } from 'tsyringe'
import { parse, StackFrame } from 'stacktrace-parser'

import { Logger } from '@services'
import { BaseError } from '@utils/classes'


@singleton()
export class ErrorHandler {

constructor(
private logger: Logger
private logger: Logger,
private client: Client
) {

// Catch all exeptions
Expand All @@ -19,19 +21,9 @@ export class ErrorHandler {

// 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 || '')
if (trace[0]) this.logger.log(
'error',
`Exception : ${error.message}\n${trace.map((frame: StackFrame) => `\t> ${frame.file}:${frame.lineNumber}`).join('\n')}`,
true
)
else this.logger.log(
'error',
'An error as occured in a unknow file\n\t> ' + error.message,
true
)

// log the error
this.logger.logError(error, "Exception");
})

// catch all Unhandled Rejection (promise)
Expand All @@ -40,18 +32,8 @@ export class ErrorHandler {
// 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 || '')
if (trace[0]) this.logger.log(
'error',
`Unhandled rejection : ${error.message}\n${trace.map((frame: StackFrame) => `\t> ${frame.file}:${frame.lineNumber}`).join('\n')}`,
true
)
else this.logger.log(
'error',
'An unhandled rejection as occured in a unknow file\n\t> ' + error,
true
)
// log the error
this.logger.logError(error, "unhandledRejection");
})
}
}
Loading