zhaoyingbo 09e352a9c1
All checks were successful
Egg Server MIflow / build-image (push) Successful in 1m5s
feat: 抽象网络请求类 & 内容转为ctx向内传递
2024-08-16 09:12:11 +00:00

29 lines
771 B
TypeScript

import db from "../../db"
import { NetError, NetToolBase } from "../../utils/netTool"
class LarkBaseService extends NetToolBase {
constructor(appName: string, requestId: string) {
super({
prefix: "https://open.f.mioffice.cn/open-apis",
requestId,
getHeaders: async () => ({
Authorization: `Bearer ${await db.tenantAccessToken.get(appName)}`,
}),
})
}
protected async request<T = any>(params: any): Promise<T> {
return super.request<T>(params).catch((error: NetError) => {
const res = {
code: error.code,
data: null,
message: error.message,
} as T
this.logger.error("larkNetTool catch error: ", JSON.stringify(res))
return res
})
}
}
export default LarkBaseService