MCPcopy Index your code
hub / github.com/supabase/auth / TestHandleResponseErrorWithHTTPError

Function TestHandleResponseErrorWithHTTPError

internal/api/errors_test.go:17–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestHandleResponseErrorWithHTTPError(t *testing.T) {
18 examples := []struct {
19 HTTPError *HTTPError
20 APIVersion string
21 ExpectedBody string
22 }{
23 {
24 HTTPError: apierrors.NewBadRequestError(apierrors.ErrorCodeBadJSON, "Unable to parse JSON"),
25 APIVersion: "",
26 ExpectedBody: "{\"code\":400,\"error_code\":\"" + apierrors.ErrorCodeBadJSON + "\",\"msg\":\"Unable to parse JSON\"}",
27 },
28 {
29 HTTPError: apierrors.NewBadRequestError(apierrors.ErrorCodeBadJSON, "Unable to parse JSON"),
30 APIVersion: "2023-12-31",
31 ExpectedBody: "{\"code\":400,\"error_code\":\"" + apierrors.ErrorCodeBadJSON + "\",\"msg\":\"Unable to parse JSON\"}",
32 },
33 {
34 HTTPError: apierrors.NewBadRequestError(apierrors.ErrorCodeBadJSON, "Unable to parse JSON"),
35 APIVersion: "2024-01-01",
36 ExpectedBody: "{\"code\":\"" + apierrors.ErrorCodeBadJSON + "\",\"message\":\"Unable to parse JSON\"}",
37 },
38 {
39 HTTPError: &HTTPError{
40 HTTPStatus: http.StatusBadRequest,
41 Message: "Uncoded failure",
42 },
43 APIVersion: "2024-01-01",
44 ExpectedBody: "{\"code\":\"" + apierrors.ErrorCodeUnknown + "\",\"message\":\"Uncoded failure\"}",
45 },
46 {
47 HTTPError: &HTTPError{
48 HTTPStatus: http.StatusInternalServerError,
49 Message: "Unexpected failure",
50 },
51 APIVersion: "2024-01-01",
52 ExpectedBody: "{\"code\":\"" + apierrors.ErrorCodeUnexpectedFailure + "\",\"message\":\"Unexpected failure\"}",
53 },
54 }
55
56 for _, example := range examples {
57 rec := httptest.NewRecorder()
58 req, err := http.NewRequest(http.MethodPost, "http://example.com", nil)
59 require.NoError(t, err)
60
61 if example.APIVersion != "" {
62 req.Header.Set(APIVersionHeaderName, example.APIVersion)
63 }
64
65 HandleResponseError(example.HTTPError, rec, req)
66
67 require.Equal(t, example.HTTPError.HTTPStatus, rec.Code)
68 require.Equal(t, example.ExpectedBody, rec.Body.String())
69 }
70}
71
72func TestRecoverer(t *testing.T) {
73 var logBuffer bytes.Buffer

Callers

nothing calls this directly

Calls 5

NewBadRequestErrorFunction · 0.92
HandleResponseErrorFunction · 0.85
SetMethod · 0.80
EqualMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…