@ruan-cat/utils 4.5.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -78,6 +78,44 @@ export enum HttpCode {
|
|
|
78
78
|
SUCCESS = 10000,
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* 请求结果分类
|
|
83
|
+
* @description
|
|
84
|
+
* 成功 失败 错误
|
|
85
|
+
*/
|
|
86
|
+
export type HttpStatus = "success" | "fail" | "error";
|
|
87
|
+
|
|
88
|
+
/** 接口请求状态是否是成功的? */
|
|
89
|
+
export function isHttpStatusSuccess(status: HttpStatus): status is "success" {
|
|
90
|
+
return status === "success";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* http码的映射存储值
|
|
95
|
+
* @description
|
|
96
|
+
* 根据业务类型存储不同的值
|
|
97
|
+
*/
|
|
98
|
+
export interface HttpCodeMessageMapValue {
|
|
99
|
+
/** 接口提示文本 */
|
|
100
|
+
message: string;
|
|
101
|
+
/** 接口请求状态 */
|
|
102
|
+
type: HttpStatus;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 请求码与请求响应文本的映射表 */
|
|
106
|
+
export const HttpCodeMessageMap: Record<HttpCode, HttpCodeMessageMapValue> = {
|
|
107
|
+
[HttpCode.UNAUTHORIZED]: { message: "未登录或登录已过期,请重新登录", type: "error" },
|
|
108
|
+
[HttpCode.FORBIDDEN]: { message: "没有相关权限", type: "error" },
|
|
109
|
+
[HttpCode.NOT_FOUND]: { message: "访问页面未找到", type: "error" },
|
|
110
|
+
[HttpCode.SERVER_ERROR]: { message: "服务器错误", type: "error" },
|
|
111
|
+
[HttpCode.PARAMS_INVALID]: { message: "上传参数异常", type: "error" },
|
|
112
|
+
[HttpCode.CONTENT_TYPE_ERR]: { message: "ContentType错误", type: "error" },
|
|
113
|
+
[HttpCode.API_UN_IMPL]: { message: "功能尚未实现", type: "error" },
|
|
114
|
+
[HttpCode.SERVER_BUSY]: { message: "服务器繁忙", type: "error" },
|
|
115
|
+
[HttpCode.FAIL]: { message: "操作失败", type: "fail" },
|
|
116
|
+
[HttpCode.SUCCESS]: { message: "操作成功", type: "success" },
|
|
117
|
+
};
|
|
118
|
+
|
|
81
119
|
/**
|
|
82
120
|
* 上传类型-请求体类型 枚举
|
|
83
121
|
* @description
|