Skip to content

Commit

Permalink
Refactor error into its own struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr Tihomirov committed Jan 7, 2017
1 parent 85f96dd commit 6f17067
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ func (o *Client) UploadFiles(ctx context.Context, rs []NamedReader) (response *R
if err != nil {
return
}
if !response.Success {
return nil, &ErrUploadFailed{response.Description, response.Errorcode}
}

return
}
Expand Down
12 changes: 12 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package owo

import "fmt"

type (
// Response contains json marshalled response from owo
Response struct {
Expand All @@ -40,8 +42,18 @@ type (
Errorcode int `json:"errorcode,omitempty"`
Description string `json:"description,omitempty"`
}

// ErrUploadFailed thrown when success flag on response is false
ErrUploadFailed struct {
Message string
ErrorCode int
}
)

func (e ErrUploadFailed) Error() string {
return fmt.Sprintf("Upload failed with code %d and message '%s'", e.ErrorCode, e.Message)
}

// WithCDN returns file url prefixed with the CDN
func (f File) WithCDN(cdn string) string {
return cdn + f.URL
Expand Down

0 comments on commit 6f17067

Please sign in to comment.