Skip to content

Commit

Permalink
fix(server): 适配器错误信息为嵌套型而导致页面显示不正确的问题 (#1275)
Browse files Browse the repository at this point in the history
**问题背景**

在适配器异常时页面统一错误处理的issue中  #1182 

如果已经是处理封装过的`grpc error`, 会在 `callOnOne`执行时统一处理为 `code =
status.INTERNAL`的错误且将errorObject直接写入details,导致部分页面出现
适配器的错误信息详细变为嵌套型对象,无法正确解析

![image](https://github.com/PKUHPC/SCOW/assets/43978285/054e0f47-8d6e-4350-81dc-676e78ac6fcf)


**修改**
统一错误处理时 判断callOnOne返回的error类型,如果是已处理过的grpc error直接抛出错误

**修改后**
前端页面可以正确获取已处理的grpc error的 code, message等,正确显示前端对应的错误信息
统一错误处理也可正常显示


![image](https://github.com/PKUHPC/SCOW/assets/43978285/0d1a0e89-4d73-4899-bfce-c583793ec3e4)

![image](https://github.com/PKUHPC/SCOW/assets/43978285/bf1591fe-1862-4f5a-bb32-26528cd7f6cb)


![image](https://github.com/PKUHPC/SCOW/assets/43978285/a209ad99-d871-42be-9ab7-c0c1ff3716a5)
  • Loading branch information
piccaSun authored and OYX-1 committed Jul 4, 2024
1 parent c53882d commit 7d19adf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .changeset/moody-nails-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@scow/portal-server": patch
"@scow/mis-server": patch
---

修复请求集群适配器接口的报错信息中出现嵌套型信息,导致页面报错信息显示不正确的问题
29 changes: 20 additions & 9 deletions apps/mis-server/src/plugins/clusters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,28 @@ export const clustersPlugin = plugin(async (f) => {

return await call(client).catch((e) => {
logger.error("Cluster ops fails at %o", e);
const reason = "Cluster ID : " + cluster + " Details : " + e;

const errorDetail = e instanceof Error ? e : JSON.stringify(e);

const reason = "Cluster ID : " + cluster + ", Details : " + errorDetail;
const clusterErrorDetails = [{
clusterId: cluster,
details: e,
details: errorDetail,
}];
throw new ServiceError({
code: status.INTERNAL,
details: reason,
metadata: scowErrorMetadata(ADAPTER_CALL_ON_ONE_ERROR,
{ clusterErrors: JSON.stringify(clusterErrorDetails) }),
});

// 统一错误处理
if (e instanceof Error) {
throw new ServiceError({
code: status.INTERNAL,
details: reason,
metadata: scowErrorMetadata(ADAPTER_CALL_ON_ONE_ERROR,
{ clusterErrors: JSON.stringify(clusterErrorDetails) }),
});
// 如果是已经封装过的grpc error, 直接抛出错误
} else {
throw e;
}

});
}),

Expand Down Expand Up @@ -134,7 +145,7 @@ export const clustersPlugin = plugin(async (f) => {

if (failed.length > 0) {
logger.error("Cluster ops fails at clusters %o", failed);
const reason = failed.map((x) => "Cluster ID : " + x.cluster + " Details : " + x.error).join("; ");
const reason = failed.map((x) => "Cluster ID : " + x.cluster + ", Details : " + x.error).join("; ");

const clusterErrorDetails = failed.map((x) => ({
clusterId: x.cluster,
Expand Down
24 changes: 17 additions & 7 deletions apps/portal-server/src/utils/clusters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,25 @@ export const callOnOne: CallOnOne = async (cluster, logger, call) => {
return await call(client).catch((e) => {
logger.error("Cluster ops fails at %o", e);

const errorDetail = e instanceof Error ? e : JSON.stringify(e);

const clusterErrorDetails = [{
clusterId: cluster,
details: e,
details: errorDetail,
}];
const reason = "Cluster ID : " + cluster + " Details : " + e;
throw new ServiceError({
code: status.INTERNAL,
details: reason,
metadata: scowErrorMetadata(ADAPTER_CALL_ON_ONE_ERROR, { clusterErrors: JSON.stringify(clusterErrorDetails) }),
});
const reason = "Cluster ID : " + cluster + ", Details : " + errorDetail;

// 统一错误处理
if (e instanceof Error) {
throw new ServiceError({
code: status.INTERNAL,
details: reason,
metadata: scowErrorMetadata(ADAPTER_CALL_ON_ONE_ERROR, { clusterErrors: JSON.stringify(clusterErrorDetails) }),
});
// 如果是已经封装过的grpc error, 直接抛出错误
} else {
throw e;
}

});
};

0 comments on commit 7d19adf

Please sign in to comment.