MCPcopy Index your code
hub / github.com/go-dev-frame/sponge / ToHTTPCode

Method ToHTTPCode

pkg/errcode/http_error.go:133–169  ·  view source on GitHub ↗

ToHTTPCode convert to http error code

()

Source from the content-addressed store, hash-verified

131
132// ToHTTPCode convert to http error code
133func (e *Error) ToHTTPCode() int {
134 switch e.Code() {
135 case Success.Code():
136 return http.StatusOK
137 case InternalServerError.Code():
138 return http.StatusInternalServerError
139 case InvalidParams.Code():
140 return http.StatusBadRequest
141 }
142
143 switch e.Code() {
144 case Unauthorized.Code(), PermissionDenied.Code():
145 return http.StatusUnauthorized
146 case TooManyRequests.Code(), LimitExceed.Code():
147 return http.StatusTooManyRequests
148 case Forbidden.Code(), AccessDenied.Code():
149 return http.StatusForbidden
150 case NotFound.Code():
151 return http.StatusNotFound
152 case Conflict.Code(), AlreadyExists.Code():
153 return http.StatusConflict
154 case TooEarly.Code():
155 return http.StatusTooEarly
156 case Timeout.Code(), DeadlineExceeded.Code():
157 return http.StatusRequestTimeout
158 case MethodNotAllowed.Code():
159 return http.StatusMethodNotAllowed
160 case ServiceUnavailable.Code():
161 return http.StatusServiceUnavailable
162 case Unimplemented.Code():
163 return http.StatusNotImplemented
164 case StatusBadGateway.Code():
165 return http.StatusBadGateway
166 }
167
168 return http.StatusInternalServerError
169}
170
171// ParseError parsing out error codes from error messages
172func ParseError(err error) *Error {

Callers 14

runResponseHTTPServerFunction · 0.80
TestRespondFunction · 0.80
OutFunction · 0.80
GetErrorCodeFunction · 0.80
TestNewErrorFunction · 0.80
TestParseErrorFunction · 0.80
handleHTTPErrorMethod · 0.80
CreateMethod · 0.80
DeleteByIDMethod · 0.80
UpdateByIDMethod · 0.80

Calls 1

CodeMethod · 0.95

Tested by 4

runResponseHTTPServerFunction · 0.64
TestRespondFunction · 0.64
TestNewErrorFunction · 0.64
TestParseErrorFunction · 0.64