Merge pull request #3665 from nspcc-dev/http-code-status-ok

rpcsrv: align default error code with C# implementation
This commit is contained in:
Anna Shaleva 2024-11-12 17:19:03 +03:00 committed by GitHub
commit dda2cafdf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 0 additions and 23 deletions

View file

@ -1,8 +1,6 @@
package rpcsrv package rpcsrv
import ( import (
"net/http"
"github.com/nspcc-dev/neo-go/pkg/neorpc" "github.com/nspcc-dev/neo-go/pkg/neorpc"
) )
@ -36,18 +34,3 @@ func (ab abstractBatch) RunForErrors(f func(jsonErr *neorpc.Error)) {
a.RunForErrors(f) a.RunForErrors(f)
} }
} }
func getHTTPCodeForError(respErr *neorpc.Error) int {
var httpCode int
switch respErr.Code {
case neorpc.BadRequestCode:
httpCode = http.StatusBadRequest
case neorpc.MethodNotFoundCode:
httpCode = http.StatusMethodNotAllowed
case neorpc.InternalServerErrorCode:
httpCode = http.StatusInternalServerError
default:
httpCode = http.StatusUnprocessableEntity
}
return httpCode
}

View file

@ -3100,12 +3100,6 @@ func (s *Server) writeHTTPServerResponse(r *params.Request, w http.ResponseWrite
if s.config.EnableCORSWorkaround { if s.config.EnableCORSWorkaround {
setCORSOriginHeaders(w.Header()) setCORSOriginHeaders(w.Header())
} }
if r.In != nil {
resp := resp.(abstract)
if resp.Error != nil {
w.WriteHeader(getHTTPCodeForError(resp.Error))
}
}
encoder := json.NewEncoder(w) encoder := json.NewEncoder(w)
err := encoder.Encode(resp) err := encoder.Encode(resp)