MCPcopy Create free account
hub / github.com/asternic/wuzapi / writeResponse

Method writeResponse

stdio.go:570–601  ·  view source on GitHub ↗
(response jsonRpcResponse)

Source from the content-addressed store, hash-verified

568 response := jsonRpcResponse{
569 JSONRPC: "2.0",
570 ID: id,
571 Error: &rpcError{
572 Code: code,
573 Message: errorMsg,
574 },
575 }
576 ss.writeResponse(response)
577}
578
579func (ss *stdioServer) writeResponse(response jsonRpcResponse) {
580 // Marshalled response as single line
581 responseBytes, err := json.Marshal(response)
582 if err != nil {
583 log.Error().Err(err).Msg("Failed to marshal response")
584 fallback := jsonRpcResponse{
585 JSONRPC: "2.0",
586 ID: response.ID,
587 Error: &rpcError{
588 Code: -32603,
589 Message: "Internal error: failed to marshal response",
590 },
591 }
592 responseBytes, err = json.Marshal(fallback)
593 if err != nil {
594 log.Error().Err(err).Msg("Failed to marshal fallback response")
595 return
596 }
597 }
598
599 // Write to stdout with newline
600 fmt.Fprintf(ss.stdout, "%s\n", string(responseBytes))
601
602 // Log with appropriate fields based on response type
603 logEvent := log.Debug().Str("id", response.ID.String())
604 if response.Error != nil {

Callers 2

sendSuccessMethod · 0.95
sendErrorMethod · 0.95

Calls 1

StringMethod · 0.80

Tested by

no test coverage detected