Follow up from "Add generic error message when not JSON"
The following discussion from !151572 (merged) should be addressed:
-
@rcrespo3 started a discussion: (+5 comments) suggestion: WDYT about writing a test for this? As an example, we could mock the error response like so:
diff --git a/spec/frontend/kubernetes_dashboard/graphql/resolvers/kubernetes_spec.js b/spec/frontend/kubernetes_dashboard/graphql/resolvers/kubernetes_spec.js index 335554020f94..3fcbde665e31 100644 --- a/spec/frontend/kubernetes_dashboard/graphql/resolvers/kubernetes_spec.js +++ b/spec/frontend/kubernetes_dashboard/graphql/resolvers/kubernetes_spec.js @@ -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', () => {