【发布时间】:2022-12-19 01:01:56
【问题描述】:
我调用了该服务,但是当我运行 npm 时,我的浏览器上什么也没显示,错误是 401,空数组...
.ts 文件
const getHrRelation = async (
auth: string,
originId: string,
location: string,
): Promise<HrRelation[]> => {
try {
const response = await axios.request({
method: 'GET',
url: `${process.env.API_GATEWAY}/hr/relation`,
headers: {
Authorization: auth,
},
responseType: 'json',
params: {
'api-version': apiVersion,
origin: originId,
location: location,
},
});
return response.data as HrRelation[];
} catch (err) {
throw processAPIError(err, {
resource: 'hr/relation',
value: `location: ${location}`,
});
}
};
export default {
getHrRelation,
};
列表文件
const hrRelationsRes = await HrRelationProvider.getHrRelation(
authorization,
origin,
location,
);
const hrRelations = rolesCodes
? hrRelationsRes.filter(elem => rolesCodes.indexOf(elem.role) > -1)
: hrRelationsRes;
if (hrRelations) {
const locationListIds = Array.from(
new Set(hrRelations.map(elem => elem.location) as string[])
);
const hrsId = Array.from(
new Set(hrRelations.map(elem => elem.hr) as string[])
);
这应该返回 hrs 列表,hr 关系本身......它怎么没有定义?
【问题讨论】:
标签: typescript api service http-status-code-401