github.com/renbou/grpcbridge@v0.0.2-0.20240416012907-bcbd8b12648a/internal/httperr/httperr.go (about) 1 package httperr 2 3 // StatusError is the default grpcbridge error implementation of interface { HTTPStatus() int }, 4 // used by the routing and transcoding components to customize returned HTTP status codes. 5 type StatusError struct { 6 Code int 7 Err error 8 } 9 10 func Status(code int, err error) *StatusError { 11 return &StatusError{Code: code, Err: err} 12 } 13 14 func (e *StatusError) Error() string { 15 return e.Err.Error() 16 } 17 18 func (e *StatusError) Unwrap() error { 19 return e.Err 20 } 21 22 func (e *StatusError) HTTPStatus() int { 23 return e.Code 24 }