协议修改
This commit is contained in:
@@ -15,7 +15,7 @@ export class ApiClient {
|
||||
}
|
||||
private constructor(private http = HttpManager.I) {}
|
||||
private get baseUrl() { return AppConfig.I.getHttpBase() }
|
||||
private get token() { return DataManager.I.getDataById<LoginData>(DataId.Login).getToken();}
|
||||
private get token() { return DataManager.I.getDataById<LoginData>(DataId.Login).token;}
|
||||
|
||||
public async call<Req, Res>(ep: Endpoint<Req, Res>, req: Req): Promise<ApiResponse<Res>> {
|
||||
const url = `${this.baseUrl}/${ep.path.replace(/^\/+/, "")}`;
|
||||
@@ -67,12 +67,12 @@ export class ApiClient {
|
||||
if (parsed && typeof parsed === "object" && typeof parsed.code === "number") {
|
||||
return {
|
||||
code: parsed.code,
|
||||
msg: parsed.msg ?? (parsed.code === 1 ? "ok" : "error"),
|
||||
data: parsed.Data as Res
|
||||
msg: parsed.msg ?? (parsed.code === 0 ? "ok" : "error"),
|
||||
data: parsed.data as Res
|
||||
};
|
||||
}
|
||||
// 否则我们包一层
|
||||
return { code: ApiCode.OK, msg: "ok", data: parsed.Data as Res };
|
||||
return { code: ApiCode.OK, msg: "ok", data: parsed.data as Res };
|
||||
} else if (ep.codec === "proto") {
|
||||
const data = ProtoCodec.decode<Res>(ep.resType!, r.body);
|
||||
// proto 场景一般没有 {code,msg} 包装,我们统一包一层
|
||||
|
||||
@@ -5,7 +5,7 @@ export interface ApiResponse<T = any> {
|
||||
}
|
||||
|
||||
export const ApiCode = {
|
||||
OK: 1,
|
||||
OK: 0,
|
||||
AUTH_EXPIRED: -401,
|
||||
HTTP_ERROR: -400,
|
||||
TIMEOUT: -408,
|
||||
|
||||
Reference in New Issue
Block a user