func fromSystemError(err tchannel.SystemError) error { switch err.Code() { case tchannel.ErrCodeCancelled, tchannel.ErrCodeBusy, tchannel.ErrCodeBadRequest: return errors.RemoteBadRequestError(err.Message()) case tchannel.ErrCodeTimeout: return errors.RemoteTimeoutError(err.Message()) default: return errors.RemoteUnexpectedError(err.Message()) } }
func getErrFromResponse(response *http.Response) error { // TODO Behavior for 300-range status codes is undefined contents, err := ioutil.ReadAll(response.Body) if err != nil { return err } if err := response.Body.Close(); err != nil { return err } // Trim the trailing newline from HTTP error messages message := strings.TrimSuffix(string(contents), "\n") if response.StatusCode >= 400 && response.StatusCode < 500 { return errors.RemoteBadRequestError(message) } if response.StatusCode == http.StatusGatewayTimeout { return errors.RemoteTimeoutError(message) } return errors.RemoteUnexpectedError(message) }