getStatusCodeFromError extracts http status code based on error, similar to how writeError was implemented.
(err error)
| 669 | |
| 670 | // getStatusCodeFromError extracts http status code based on error, similar to how writeError was implemented. |
| 671 | func getStatusCodeFromError(err error) int { |
| 672 | switch err { |
| 673 | case context.Canceled: |
| 674 | return util_api.StatusClientClosedRequest |
| 675 | case context.DeadlineExceeded: |
| 676 | return http.StatusGatewayTimeout |
| 677 | default: |
| 678 | if util.IsRequestBodyTooLarge(err) { |
| 679 | return http.StatusRequestEntityTooLarge |
| 680 | } |
| 681 | } |
| 682 | resp, ok := httpgrpc.HTTPResponseFromError(err) |
| 683 | if ok { |
| 684 | return int(resp.Code) |
| 685 | } |
| 686 | return http.StatusInternalServerError |
| 687 | } |
no test coverage detected