Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Change successful schema add status to 200 #1106

Merged
merged 2 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions api/http/handlerfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func execGQLHandler(rw http.ResponseWriter, req *http.Request) {
// This however is not a failing condition as not setting the content-type header
// should still make for a valid request and hit our default switch case.
if err != nil && err.Error() != "mime: no media type" {
handleErr(req.Context(), rw, err, http.StatusBadRequest)
handleErr(req.Context(), rw, err, http.StatusInternalServerError)
return
}

Expand Down Expand Up @@ -126,7 +126,7 @@ func execGQLHandler(rw http.ResponseWriter, req *http.Request) {
}
body, err := io.ReadAll(req.Body)
if err != nil {
handleErr(req.Context(), rw, errors.WithStack(err), http.StatusBadRequest)
handleErr(req.Context(), rw, errors.WithStack(err), http.StatusInternalServerError)
return
}
request = string(body)
Expand Down Expand Up @@ -157,7 +157,7 @@ func execGQLHandler(rw http.ResponseWriter, req *http.Request) {
func loadSchemaHandler(rw http.ResponseWriter, req *http.Request) {
sdl, err := io.ReadAll(req.Body)
if err != nil {
handleErr(req.Context(), rw, err, http.StatusBadRequest)
handleErr(req.Context(), rw, err, http.StatusInternalServerError)
return
}

Expand All @@ -169,15 +169,15 @@ func loadSchemaHandler(rw http.ResponseWriter, req *http.Request) {

err = db.AddSchema(req.Context(), string(sdl))
if err != nil {
handleErr(req.Context(), rw, err, http.StatusBadRequest)
handleErr(req.Context(), rw, err, http.StatusInternalServerError)
return
}

sendJSON(
req.Context(),
rw,
simpleDataResponse("result", "success"),
http.StatusBadRequest,
http.StatusOK,
)
}

Expand Down Expand Up @@ -207,13 +207,13 @@ func getBlockHandler(rw http.ResponseWriter, req *http.Request) {

block, err := db.Blockstore().Get(req.Context(), cID)
if err != nil {
handleErr(req.Context(), rw, err, http.StatusBadRequest)
handleErr(req.Context(), rw, err, http.StatusInternalServerError)
return
}

nd, err := dag.DecodeProtobuf(block.RawData())
if err != nil {
handleErr(req.Context(), rw, err, http.StatusBadRequest)
handleErr(req.Context(), rw, err, http.StatusInternalServerError)
return
}

Expand Down
32 changes: 16 additions & 16 deletions api/http/handlerfuncs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ func TestExecGQLWithMockBody(t *testing.T) {
Method: "POST",
Path: GraphQLPath,
Body: &mockReadCloser,
ExpectedStatus: 400,
ExpectedStatus: 500,
ResponseData: &errResponse,
})

assert.Contains(t, errResponse.Errors[0].Extensions.Stack, "error reading")
assert.Equal(t, http.StatusBadRequest, errResponse.Errors[0].Extensions.Status)
assert.Equal(t, "Bad Request", errResponse.Errors[0].Extensions.HTTPError)
assert.Equal(t, http.StatusInternalServerError, errResponse.Errors[0].Extensions.Status)
assert.Equal(t, "Internal Server Error", errResponse.Errors[0].Extensions.HTTPError)
assert.Equal(t, "error reading", errResponse.Errors[0].Message)
}

Expand All @@ -228,14 +228,14 @@ mutation {
Method: "POST",
Path: GraphQLPath,
Body: buf,
ExpectedStatus: 400,
ExpectedStatus: 500,
Headers: map[string]string{"Content-Type": contentTypeJSON + "; this-is-wrong"},
ResponseData: &errResponse,
})

assert.Contains(t, errResponse.Errors[0].Extensions.Stack, "mime: invalid media parameter")
assert.Equal(t, http.StatusBadRequest, errResponse.Errors[0].Extensions.Status)
assert.Equal(t, "Bad Request", errResponse.Errors[0].Extensions.HTTPError)
assert.Equal(t, http.StatusInternalServerError, errResponse.Errors[0].Extensions.Status)
assert.Equal(t, "Internal Server Error", errResponse.Errors[0].Extensions.HTTPError)
assert.Equal(t, "mime: invalid media parameter", errResponse.Errors[0].Message)
}

Expand Down Expand Up @@ -565,13 +565,13 @@ func TestLoadSchemaHandlerWithReadBodyError(t *testing.T) {
Method: "POST",
Path: SchemaLoadPath,
Body: &mockReadCloser,
ExpectedStatus: 400,
ExpectedStatus: 500,
ResponseData: &errResponse,
})

assert.Contains(t, errResponse.Errors[0].Extensions.Stack, "error reading")
assert.Equal(t, http.StatusBadRequest, errResponse.Errors[0].Extensions.Status)
assert.Equal(t, "Bad Request", errResponse.Errors[0].Extensions.HTTPError)
assert.Equal(t, http.StatusInternalServerError, errResponse.Errors[0].Extensions.Status)
assert.Equal(t, "Internal Server Error", errResponse.Errors[0].Extensions.HTTPError)
assert.Equal(t, "error reading", errResponse.Errors[0].Message)
}

Expand Down Expand Up @@ -630,13 +630,13 @@ types user {
Method: "POST",
Path: SchemaLoadPath,
Body: buf,
ExpectedStatus: 400,
ExpectedStatus: 500,
ResponseData: &errResponse,
})

assert.Contains(t, errResponse.Errors[0].Extensions.Stack, "Syntax Error GraphQL (2:1) Unexpected Name")
assert.Equal(t, http.StatusBadRequest, errResponse.Errors[0].Extensions.Status)
assert.Equal(t, "Bad Request", errResponse.Errors[0].Extensions.HTTPError)
assert.Equal(t, http.StatusInternalServerError, errResponse.Errors[0].Extensions.Status)
assert.Equal(t, "Internal Server Error", errResponse.Errors[0].Extensions.HTTPError)
assert.Equal(
t,
"Syntax Error GraphQL (2:1) Unexpected Name \"types\"\n\n1: \n2: types user {\n ^\n3: \\u0009name: String\n",
Expand Down Expand Up @@ -666,7 +666,7 @@ type user {
Method: "POST",
Path: SchemaLoadPath,
Body: buf,
ExpectedStatus: 400,
ExpectedStatus: 200,
ResponseData: &resp,
})

Expand Down Expand Up @@ -759,13 +759,13 @@ func TestGetBlockHandlerWithGetBlockstoreError(t *testing.T) {
Method: "GET",
Path: BlocksPath + "/bafybeidembipteezluioakc2zyke4h5fnj4rr3uaougfyxd35u3qzefzhm",
Body: nil,
ExpectedStatus: 400,
ExpectedStatus: 500,
ResponseData: &errResponse,
})

assert.Contains(t, errResponse.Errors[0].Extensions.Stack, "ipld: could not find bafybeidembipteezluioakc2zyke4h5fnj4rr3uaougfyxd35u3qzefzhm")
assert.Equal(t, http.StatusBadRequest, errResponse.Errors[0].Extensions.Status)
assert.Equal(t, "Bad Request", errResponse.Errors[0].Extensions.HTTPError)
assert.Equal(t, http.StatusInternalServerError, errResponse.Errors[0].Extensions.Status)
assert.Equal(t, "Internal Server Error", errResponse.Errors[0].Extensions.HTTPError)
assert.Equal(t, "ipld: could not find bafybeidembipteezluioakc2zyke4h5fnj4rr3uaougfyxd35u3qzefzhm", errResponse.Errors[0].Message)
}

Expand Down