Show graphql error message (#1852)

Co-authored-by: StephaneBischoffSSENSE <stephane.bischoff@ssense.com>
Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
This commit is contained in:
Stephane
2021-10-03 22:31:47 -04:00
committed by GitHub
parent 2ab1d3dbfa
commit 06161bc963
4 changed files with 38 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
import axios from "axios"
import axiosStrategy from "../AxiosStrategy"
import { JsonFormattedError } from "~/helpers/utils/JsonFormattedError"
jest.mock("axios")
jest.mock("~/newstore/settings", () => {
@@ -42,18 +43,34 @@ describe("axiosStrategy", () => {
await expect(axiosStrategy({})).resolves.toBeDefined()
})
test("rejects cancel errors with text 'cancellation'", () => {
test("rejects cancel errors with text 'cancellation'", async () => {
axios.isCancel.mockReturnValueOnce(true)
axios.mockRejectedValue("err")
expect(axiosStrategy({})).rejects.toBe("cancellation")
await expect(axiosStrategy({})).rejects.toBe("cancellation")
})
test("rejects non-cancellation errors as-is", () => {
test("rejects non-cancellation errors as-is", async () => {
axios.isCancel.mockReturnValueOnce(false)
axios.mockRejectedValue("err")
expect(axiosStrategy({})).rejects.toBe("err")
await expect(axiosStrategy({})).rejects.toBe("err")
})
test("non-cancellation errors that have response data are thrown", async () => {
const errorResponse = { error: "errr" }
axios.isCancel.mockReturnValueOnce(false)
axios.mockRejectedValue({
response: {
data: Buffer.from(JSON.stringify(errorResponse), "utf8").toString(
"base64"
),
},
})
await expect(axiosStrategy({})).rejects.toMatchObject(
new JsonFormattedError(errorResponse)
)
})
})
})