ToHTTPCode convert to http error code
()
| 131 | |
| 132 | // ToHTTPCode convert to http error code |
| 133 | func (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 |
| 172 | func ParseError(err error) *Error { |