MCPcopy Create free account
hub / github.com/erpc/erpc / sendErrorResponse

Method sendErrorResponse

test/fake_server.go:248–271  ·  view source on GitHub ↗
(w http.ResponseWriter, id interface{}, code int, message string)

Source from the content-addressed store, hash-verified

246}
247
248func (fs *FakeServer) sendErrorResponse(w http.ResponseWriter, id interface{}, code int, message string) {
249 fs.mu.Lock()
250 fs.requestsFailed++
251 fs.mu.Unlock()
252
253 response := JSONRPCResponse{
254 Jsonrpc: "2.0",
255 Error: map[string]interface{}{"code": code, "message": message},
256 ID: id,
257 }
258 w.Header().Set("Content-Type", "application/json")
259 buf := &bytes.Buffer{}
260 if err := json.NewEncoder(buf).Encode(response); err != nil {
261 log.Error().Err(err).Msg("Failed to encode response")
262 return
263 }
264 bt := buf.Bytes()
265 if len(bt) > 1024 {
266 log.Info().Str("response", string(bt[:1024])).Msg("Response sent (partial)")
267 } else {
268 log.Info().Str("response", string(bt)).Msg("Response sent")
269 }
270 w.Write(bt)
271}
272
273func (fs *FakeServer) findMatchingSample(req JSONRPCRequest) *JSONRPCResponse {
274 for _, sample := range fs.samples {

Callers 3

handleRequestMethod · 0.95
handleBatchRequestMethod · 0.95
handleSingleRequestMethod · 0.95

Calls 6

LockMethod · 0.65
UnlockMethod · 0.65
SetMethod · 0.65
ErrorMethod · 0.65
HeaderMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected