Skip to content

Commit

Permalink
refactor: add params for ErrorCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
chettoy committed May 11, 2023
1 parent 5293400 commit 8c07385
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/internal/app/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class ToolsQuestionBank implements QuestionBank {
success: (result: any) => {
Application.App.log.Info("答案已记录");
},
error: () => {
error: (e: any) => {
Application.App.log.Info("答案未记录");
}
});
Expand Down Expand Up @@ -210,7 +210,8 @@ export class ToolsQuestionBank implements QuestionBank {
return resolve({ status: retStatus, answer: answer });
}
},
error: () => {
error: (e: any) => {
console.log(e);
return resolve({ status: "network", answer: answer });
}
});
Expand Down
14 changes: 7 additions & 7 deletions src/internal/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AppName, Application } from "../application";
import { SystemConfig } from "@App/config";

export type RequestCallback = (body: any) => void
export type ErrorCallback = () => void
export type ErrorCallback = (reason: any) => void

export interface RequestInfo extends RequestInit {
url?: string
Expand All @@ -24,8 +24,8 @@ export class HttpUtils {
}
}).then(body => {
info.success && info.success(body)
}).catch(() => {
info.error && info.error()
}).catch(reason => {
info.error && info.error(reason)
});
return;
}
Expand Down Expand Up @@ -66,15 +66,15 @@ export class HttpUtils {
if (info.json) {
let ret = JSON.parse(response.responseText);
if (HttpUtils.errorCode(ret)) {
info.error && info.error();
info.error && info.error(ret);
return
}
info.success && info.success(ret);
} else {
info.success && info.success(response.responseText);
}
} else {
info.error && info.error();
info.error && info.error(response);
}
}
};
Expand All @@ -85,13 +85,13 @@ export class HttpUtils {
if (data.code == 0) {
if (info.json) {
if (HttpUtils.errorCode(data.body)) {
info.error && info.error();
info.error && info.error(data.body);
return
}
}
info.success && info.success(data.body);
} else {
info.error && info.error();
info.error && info.error(data);
}
});
client.Send({
Expand Down

0 comments on commit 8c07385

Please sign in to comment.