Skip to content

Commit

Permalink
Merge pull request #21 from srvc/creasty/v4.0.0
Browse files Browse the repository at this point in the history
v4.0.0
  • Loading branch information
creasty authored Mar 26, 2019
2 parents 07e504e + 1fa73da commit 685e8c9
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 146 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,37 +297,37 @@ import (
// ReportError handles an error, changes status code based on the error,
// and reports to an external service if necessary
func ReportError(c *gin.Context, err error) {
appErr := fail.Unwrap(err)
if appErr == nil {
failErr := fail.Unwrap(err)
if failErr == nil {
// As it's a "raw" error, `StackTrace` field left unset.
// And it should be always reported
appErr = &fail.Error{
failErr = &fail.Error{
Err: err,
}
}

convertAppError(appErr)
convertFailError(failErr)

// Send the error to an external service
if !appErr.Ignorable {
go uploadAppError(c.Copy(), appErr)
if !failErr.Ignorable {
go uploadFailError(c.Copy(), failErr)
}

// Expose an error message in the header
if msg := appErr.LastMessage(); msg != "" {
if msg := failErr.LastMessage(); msg != "" {
c.Header("X-App-Error", msg)
}

// Set status code accordingly
switch code := appErr.Code.(type) {
switch code := failErr.Code.(type) {
case int:
c.Status(code)
default:
c.Status(http.StatusInternalServerError)
}
}

func convertAppError(err *fail.Error) {
func convertFailError(err *fail.Error) {
// If the error is from ORM and it says "no record found,"
// override status code to 404
if err.Err == gorm.ErrRecordNotFound {
Expand All @@ -336,7 +336,7 @@ func convertAppError(err *fail.Error) {
}
}

func uploadAppError(c *gin.Context, err *fail.Error) {
func uploadFailError(c *gin.Context, err *fail.Error) {
// By using readbody, you can retrive an original request body
// even when c.Request.Body had been read
body := readbody.Get(c)
Expand Down
6 changes: 0 additions & 6 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ func (e *Error) LastMessage() string {
return e.Messages[0]
}

// FullMessage is marked as deprecated in favor of `Error`.
// This method will be removed in the next major release.
func (e *Error) FullMessage() string {
return e.Error()
}

// Wrap returns an error annotated with a stack trace from the point it was called,
// and with the specified annotators.
// It returns nil if err is nil.
Expand Down
Loading

0 comments on commit 685e8c9

Please sign in to comment.