Skip to content

Commit

Permalink
export lib error to get its status code
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed Jul 11, 2018
1 parent e385834 commit bb7c25e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,28 @@ import (
ehttp "github.com/topfreegames/extensions/http"
)

type requestError struct {
// RequestError contains code and body of a request that failed
type RequestError struct {
statusCode int
body string
}

func newRequestError(statusCode int, body string) *requestError {
return &requestError{
func newRequestError(statusCode int, body string) *RequestError {
return &RequestError{
statusCode: statusCode,
body: body,
}
}

func (r *requestError) Error() string {
func (r *RequestError) Error() string {
return fmt.Sprintf("Request error. Status code: %d. Body: %s", r.statusCode, r.body)
}

// Status returns the status code of the error
func (r *RequestError) Status() int {
return r.statusCode
}

// Podium is a struct that represents a podium API application
type Podium struct {
httpClient *http.Client
Expand Down

0 comments on commit bb7c25e

Please sign in to comment.