Skip to content
代码片段 群组 项目
未验证 提交 5f3d8dc4 编辑于 作者: Deepika Guliani's avatar Deepika Guliani 提交者: GitLab
浏览文件

Merge branch...

Merge branch '438572_Kubernetes_Dashboard_tries_to_parse_HTML_as_JSON_for_failed_K8s_API_queries' into 'master' 

Add a generic error message when the error response is not of JSON type

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/151572



Merged-by: default avatarDeepika Guliani <dguliani@gitlab.com>
Approved-by: default avatarPhillip Wells <pwells@gitlab.com>
Approved-by: default avatarRudy Crespo <rcrespo@gitlab.com>
Approved-by: default avatarDeepika Guliani <dguliani@gitlab.com>
Reviewed-by: default avatarRudy Crespo <rcrespo@gitlab.com>
Co-authored-by: default avatarAnton Kalmykov <anton.kalmykov@proton.me>
No related branches found
No related tags found
无相关合并请求
......@@ -8,12 +8,23 @@ import {
} from '@gitlab/cluster-client';
import { connectionStatus } from '~/environments/graphql/resolvers/kubernetes/constants';
import { updateConnectionStatus } from '~/environments/graphql/resolvers/kubernetes/k8s_connection_status';
import { s__ } from '~/locale';
export const handleClusterError = async (err) => {
if (!err.response) {
throw err;
}
const contentType = err.response.headers.get('Content-Type');
if (contentType !== 'application/json') {
throw new Error(
s__(
'KubernetesDashboard|There was a problem fetching cluster information. Refresh the page and try again.',
),
);
}
const errorData = await err.response.json();
throw errorData;
};
......
......@@ -29850,6 +29850,9 @@ msgstr ""
msgid "KubernetesDashboard|Suspended"
msgstr ""
 
msgid "KubernetesDashboard|There was a problem fetching cluster information. Refresh the page and try again."
msgstr ""
msgid "KubernetesDashboard|View projects"
msgstr ""
 
......@@ -117,6 +117,20 @@ describe('~/frontend/environments/graphql/resolvers', () => {
mockResolvers.Query.k8sDashboardPods(null, { configuration }, { client }),
).rejects.toThrow('API error');
});
it('should return a generic error message if the error response is not of JSON type', async () => {
jest.spyOn(CoreV1Api.prototype, 'listCoreV1PodForAllNamespaces').mockRejectedValue({
response: {
headers: new Headers({ 'Content-Type': 'application/pdf' }),
},
});
await expect(
mockResolvers.Query.k8sDashboardPods(null, { configuration }, { client }),
).rejects.toThrow(
'There was a problem fetching cluster information. Refresh the page and try again.',
);
});
});
describe('k8sDeployments', () => {
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册