Skip to content

Commit

Permalink
Merge pull request #15 from r3it/todo-#124
Browse files Browse the repository at this point in the history
I could confirm that there is no problem.
I merged this pull request.

Thank you.
  • Loading branch information
cy-kaneko authored Oct 5, 2017
2 parents 757fe32 + 3e869b4 commit 7020eaa
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ type AppError struct {
Message string `json:"message"` // Human readable message.
Id string `json:"id"` // A unique error ID.
Code string `json:"code"` // For machines.
Errors string `json:"errors"` // Error Description.
}

func (e *AppError) Error() string {
if len(e.Message) == 0 {
return "HTTP error: " + e.HttpStatus
}
return fmt.Sprintf("AppError: %d [%s] %s (%s)",
e.HttpStatusCode, e.Code, e.Message, e.Id)
return fmt.Sprintf("AppError: %d [%s] %s (%s) %s",
e.HttpStatusCode, e.Code, e.Message, e.Id, e.Errors)
}

type UpdateKeyField interface {
Expand Down Expand Up @@ -209,10 +210,26 @@ func parseResponse(resp *http.Response) ([]byte, error) {
HttpStatusCode: resp.StatusCode,
}
}

//Get other than the Errors property
var ae AppError
json.Unmarshal(body, &ae)
ae.HttpStatus = resp.Status
ae.HttpStatusCode = resp.StatusCode

//Get the Errors property
var errors interface{}
json.Unmarshal(body, &errors)
msg := errors.(map[string]interface{})
v, ok := msg["errors"]
//If the Errors property exists
if ok {
result, err := json.Marshal(v)
if err != nil {
return nil, err
}
ae.Errors = string(result)
}
return nil, &ae
}
return body, nil
Expand Down

0 comments on commit 7020eaa

Please sign in to comment.