Skip to content

Commit

Permalink
Fix http error type generation
Browse files Browse the repository at this point in the history
  • Loading branch information
maestre3d committed Oct 24, 2021
1 parent 9d743f2 commit c61424e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions http_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ func NewHttpError(errType, instance string, err error) HttpError {
}

code = GetHttpStatusCode(customErr)
errHttpType = getHttpErrorType(errType, code)
return HttpError{
Type: errHttpType,
Title: customErr.Title(),
Status: getHttpDddErrorType(customErr, code),
Status: getHttpDddErrorStatus(customErr, code),
StatusCode: code,
Detail: customErr.Description(),
Instance: instance,
Expand All @@ -61,7 +62,7 @@ func getHttpErrorType(rootType string, status int) string {
// retrieves a status name from an Error or a generic HTTP problem object type.
//
// For more information, go to: https://datatracker.ietf.org/doc/html/rfc7807#section-4.2
func getHttpDddErrorType(err Error, status int) string {
func getHttpDddErrorStatus(err Error, status int) string {
if statusName := err.Status(); statusName != "" {
return statusName
}
Expand Down
13 changes: 13 additions & 0 deletions http_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ var newHttpErrorTestSuite = []struct {
Instance: "/users/12345/msg/abc",
},
},
{
InErrType: "",
InInstance: "/users/12345/msg/abc",
InErr: NewNotFound("foo").SetStatus("FooNotFound"),
ExpHttpErr: HttpError{
Type: "Not Found",
Title: "Resource not found",
Status: "FooNotFound",
StatusCode: http.StatusNotFound,
Detail: "The resource foo was not found",
Instance: "/users/12345/msg/abc",
},
},
{
InErrType: "https://neutrinocorp.org/iam/probs/required",
InInstance: "/users/12345/msg/abc",
Expand Down

0 comments on commit c61424e

Please sign in to comment.