MCPcopy Create free account
hub / github.com/go-dev-frame/sponge / ErrToHTTP

Method ErrToHTTP

pkg/errcode/http_error.go:61–71  ·  view source on GitHub ↗

ErrToHTTP convert to standard error add ToHTTPCodeLabel to error message, use it if you need to convert to standard HTTP status code, if there is a parameter 'msg', it will replace the original message. Tips: you can call the GetErrorCode function to get the standard HTTP status code.

(msg ...string)

Source from the content-addressed store, hash-verified

59// if there is a parameter 'msg', it will replace the original message.
60// Tips: you can call the GetErrorCode function to get the standard HTTP status code.
61func (e *Error) ErrToHTTP(msg ...string) error {
62 message := e.msg
63 if len(msg) > 0 {
64 message = strings.Join(msg, ", ")
65 }
66
67 if len(e.details) == 0 {
68 return fmt.Errorf("code = %d, msg = %s%s", e.code, message, ToHTTPCodeLabel)
69 }
70 return fmt.Errorf("code = %d, msg = %s, details = %v%s", e.code, message, strings.Join(e.details, ", "), ToHTTPCodeLabel)
71}
72
73// Code get error code
74func (e *Error) Code() int {

Callers 5

TestNewErrorFunction · 0.95
runHTTPServerFunction · 0.45
TestParseErrorFunction · 0.45
TestGetErrorCodeFunction · 0.45
TestGetStatusCodeFunction · 0.45

Calls 1

ErrorfMethod · 0.80

Tested by 5

TestNewErrorFunction · 0.76
runHTTPServerFunction · 0.36
TestParseErrorFunction · 0.36
TestGetErrorCodeFunction · 0.36
TestGetStatusCodeFunction · 0.36