Skip to content

Commit

Permalink
fix: fixed recusrive err
Browse files Browse the repository at this point in the history
  • Loading branch information
ConsoleTVs committed Apr 3, 2024
1 parent 02548f5 commit 521f76d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
18 changes: 1 addition & 17 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,7 @@ func writeHeaders(writer http.ResponseWriter, builder Builder) {

func DefaultResponderHandler(writer http.ResponseWriter, request *http.Request, builder Builder) {
if builder.err != nil {
if builder, ok := builder.err.(Builder); ok {
builder.Handle(writer, request)

return
}

if responder, ok := builder.err.(Responder); ok {
responder.
Respond(request).
Handle(writer, request)

return
}

NewProblem(builder.err, builder.status).
Respond(request).
Handle(writer, request)
handleError(writer, request, builder.err)

return
}
Expand Down
12 changes: 11 additions & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,21 @@ func handleError(writer http.ResponseWriter, request *http.Request, err error) {
responder.
Respond(request).
Handle(writer, request)

return
}

Failed(err).Handle(writer, request)
NewProblem(err, http.StatusInternalServerError).
Respond(request).
Handle(writer, request)
}

func (handler Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
handleError(writer, request, handler(request))
}

func HandlerFunc(handler Handler) http.HandlerFunc {
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
handleError(writer, request, handler(request))
})
}

0 comments on commit 521f76d

Please sign in to comment.