Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit a437bde

Browse files
author
Matt Heisig
committed
Simplify the response code check
1 parent de85cf1 commit a437bde

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

rye.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ func (m *MWHandler) do(w http.ResponseWriter, r *http.Request, handler Handler)
9999
func() {
100100
statusCode := "2xx"
101101
startTime := time.Now()
102-
resp = handler(w, r)
103102

104-
if resp != nil {
103+
if resp = handler(w, r); resp != nil {
105104
func() {
106105
// Stop execution if it's passed
107106
if resp.StopExecution {
@@ -127,13 +126,12 @@ func (m *MWHandler) do(w http.ResponseWriter, r *http.Request, handler Handler)
127126
}
128127

129128
// Write the error out
130-
statusCode = strconv.Itoa(resp.StatusCode)
131129
WriteJSONStatus(w, "error", resp.Error(), resp.StatusCode)
132130
}()
133-
}
134131

135-
if resp != nil && resp.StatusCode > 0 {
136-
statusCode = strconv.Itoa(resp.StatusCode)
132+
if resp.StatusCode > 0 {
133+
statusCode = strconv.Itoa(resp.StatusCode)
134+
}
137135
}
138136

139137
handlerName := getFuncName(handler)

0 commit comments

Comments
 (0)