Skip to content

Commit 2e42d4c

Browse files
committed
add response checker
1 parent e96dd9e commit 2e42d4c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

RequestChainHandler.go

+8
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ import (
99

1010
// RequestChainHandler chains all handler
1111
func RequestChainHandler(responseHandler ResponseHandler, handlers ...Handler) httprouter.Handle {
12+
return RequestChainHandlerWithResponseCheck(false, responseHandler, handlers...)
13+
}
14+
15+
// RequestChainHandlerWithResponseCheck chains all handler and check every response
16+
func RequestChainHandlerWithResponseCheck(checkResponseOfEveryHandler bool, responseHandler ResponseHandler, handlers ...Handler) httprouter.Handle {
1217
return httprouter.Handle(func(writer http.ResponseWriter, request *http.Request, params httprouter.Params) {
1318
payload := Response{}
1419

1520
// iterate all handlers
1621
for _, handler := range handlers {
1722
handler(&payload, request, params)
23+
if checkResponseOfEveryHandler && (payload.Status.Code != http.StatusOK && payload.Status.Code != 0) {
24+
break
25+
}
1826
}
1927

2028
// pass responseHandler

0 commit comments

Comments
 (0)