CodeFromHTTPStatus converts an HTTP response status into the corresponding gRPC error code.
(status int)
| 158 | // CodeFromHTTPStatus converts an HTTP response status into the corresponding |
| 159 | // gRPC error code. |
| 160 | func CodeFromHTTPStatus(status int) codes.Code { |
| 161 | switch status { |
| 162 | case http.StatusOK: |
| 163 | return codes.OK |
| 164 | case http.StatusTooManyRequests: |
| 165 | return codes.ResourceExhausted |
| 166 | case http.StatusRequestTimeout: |
| 167 | return codes.DeadlineExceeded |
| 168 | case http.StatusInternalServerError: |
| 169 | return codes.Unknown |
| 170 | case http.StatusBadRequest: |
| 171 | return codes.InvalidArgument |
| 172 | case http.StatusNotFound: |
| 173 | return codes.NotFound |
| 174 | case http.StatusConflict: |
| 175 | return codes.AlreadyExists |
| 176 | case http.StatusForbidden: |
| 177 | return codes.PermissionDenied |
| 178 | case http.StatusUnauthorized: |
| 179 | return codes.Unauthenticated |
| 180 | case http.StatusPreconditionFailed: |
| 181 | return codes.FailedPrecondition |
| 182 | case http.StatusNotImplemented: |
| 183 | return codes.Unimplemented |
| 184 | case http.StatusServiceUnavailable: |
| 185 | return codes.Unavailable |
| 186 | default: |
| 187 | return codes.Code(uint32(status)) |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | func ToGRPC(er error) error { |
| 192 | if er == nil { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…