mirror of
https://github.com/whyour/qinglong.git
synced 2026-06-30 20:35:09 +08:00
修改 QLAPI 调用校验
This commit is contained in:
+23
-3
@@ -35,7 +35,7 @@ class GrpcClient {
|
||||
'getCronDetail',
|
||||
'createCron',
|
||||
'updateCron',
|
||||
'deleteCrons'
|
||||
'deleteCrons',
|
||||
];
|
||||
|
||||
#client;
|
||||
@@ -79,7 +79,7 @@ class GrpcClient {
|
||||
#promisifyMethod(methodName) {
|
||||
const capitalizedMethod =
|
||||
methodName.charAt(0).toUpperCase() + methodName.slice(1);
|
||||
const grpcMethod = this.#client[capitalizedMethod].bind(this.#client);
|
||||
const method = this.#client[capitalizedMethod].bind(this.#client);
|
||||
|
||||
return async (params = {}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -88,7 +88,7 @@ class GrpcClient {
|
||||
Date.now() + GrpcClient.#config.defaultTimeout,
|
||||
);
|
||||
|
||||
grpcMethod(params, metadata, { deadline }, (error, response) => {
|
||||
method(params, metadata, { deadline }, (error, response) => {
|
||||
if (error) {
|
||||
return reject(error);
|
||||
}
|
||||
@@ -131,4 +131,24 @@ process.on('SIGINT', () => {
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
if (reason instanceof Error) {
|
||||
if (reason.stack) {
|
||||
const relevantStack = reason.stack
|
||||
.split('\n')
|
||||
.filter((line) => {
|
||||
return (
|
||||
!line.includes('node:internal') &&
|
||||
!line.includes('node_modules/@grpc') &&
|
||||
!line.includes('processTicksAndRejections')
|
||||
);
|
||||
})
|
||||
.join('\n');
|
||||
console.error(relevantStack);
|
||||
}
|
||||
} else {
|
||||
console.error(reason);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = grpcClient.getApi();
|
||||
|
||||
@@ -29,14 +29,14 @@ def error_handler(func):
|
||||
f'"{k}": {v.__name__}' for k, v in required_fields.items()
|
||||
)
|
||||
raise Exception(
|
||||
f"unknown error: {func_name}() requires a dictionary with parameters: {{{fields_str}}}"
|
||||
f"{func_name}() requires a dictionary with parameters: {{{fields_str}}}"
|
||||
) from None
|
||||
raise Exception(f"unknown error: {str(e)}") from None
|
||||
raise Exception(f"{str(e)}") from None
|
||||
except Exception as e:
|
||||
error_msg = str(e)
|
||||
if "Error:" in error_msg:
|
||||
error_msg = error_msg.split("Error:")[-1].split("\n")[0].strip()
|
||||
raise Exception(f"unknown error: {error_msg}") from None
|
||||
raise Exception(f"{error_msg}") from None
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
Reference in New Issue
Block a user