chore: add DataWrongError
This commit is contained in:
@@ -4,6 +4,7 @@ import * as SocketIo from "socket.io"
|
|||||||
import ApiCallbackMessage from "./ApiCallbackMessage.ts"
|
import ApiCallbackMessage from "./ApiCallbackMessage.ts"
|
||||||
import EventCallbackFunction from "../typedef/EventCallbackFunction.ts"
|
import EventCallbackFunction from "../typedef/EventCallbackFunction.ts"
|
||||||
import BaseApi from "./BaseApi.ts"
|
import BaseApi from "./BaseApi.ts"
|
||||||
|
import DataWrongError from "./DataWrongError.ts";
|
||||||
|
|
||||||
export default class ApiManager {
|
export default class ApiManager {
|
||||||
static httpServer: HttpServerLike
|
static httpServer: HttpServerLike
|
||||||
@@ -40,11 +41,11 @@ export default class ApiManager {
|
|||||||
|
|
||||||
return callback(this.event_listeners[name]?.(args))
|
return callback(this.event_listeners[name]?.(args))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
const err = e as Error
|
||||||
try {
|
try {
|
||||||
callback({
|
callback({
|
||||||
code: 500,
|
code: err instanceof DataWrongError ? 400 : 500,
|
||||||
msg: "錯誤: " + e
|
msg: "錯誤: " + err.message
|
||||||
})
|
})
|
||||||
} catch(_e) {}
|
} catch(_e) {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user