(r *Route, next *Route)
| 157 | } |
| 158 | |
| 159 | func overlapRoute(r *Route, next *Route) { |
| 160 | next.BuildHandlers() |
| 161 | nextHandlers := next.Handlers[0:] |
| 162 | |
| 163 | isErrorRoutes := r.StatusCode > 0 && next.StatusCode > 0 |
| 164 | |
| 165 | decisionHandler := func(ctx *context.Context) { |
| 166 | ctx.Next() |
| 167 | |
| 168 | if isErrorRoutes { // fixes issue #1602. |
| 169 | // If it's an error we don't need to reset (see defaultOverlapFilter) |
| 170 | // its status code(!) and its body, we just check if it was proceed or not. |
| 171 | if !ctx.IsStopped() { |
| 172 | return |
| 173 | } |
| 174 | } else { |
| 175 | prevStatusCode := ctx.GetStatusCode() |
| 176 | |
| 177 | if !defaultOverlapFilter(ctx) { |
| 178 | return |
| 179 | } |
| 180 | // set the status code that it was stopped with. |
| 181 | // useful for dependencies with StopWithStatus(XXX) |
| 182 | // instead of raw ctx.StopExecution(). |
| 183 | // The func_result now also catch the last registered status code |
| 184 | // of the chain, unless the controller returns an integer. |
| 185 | // See _examples/authenticated-controller. |
| 186 | if prevStatusCode > 0 { |
| 187 | // An exception when stored error |
| 188 | // exists and it's type of ErrNotFound. |
| 189 | // Example: |
| 190 | // Version was not found: |
| 191 | // we need to be able to send the status on the last not found version |
| 192 | // but reset the status code if a next available matched version was found. |
| 193 | // see the versioning package. |
| 194 | if !errors.Is(ctx.GetErr(), context.ErrNotFound) { |
| 195 | ctx.StatusCode(prevStatusCode) |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | ctx.SetErr(nil) // clear any stored error. |
| 201 | // Set the route to the next one and execute it. |
| 202 | ctx.SetCurrentRoute(next.ReadOnly) |
| 203 | ctx.HandlerIndex(0) |
| 204 | ctx.Do(nextHandlers) |
| 205 | } |
| 206 | |
| 207 | r.builtinBeginHandlers = append(context.Handlers{decisionHandler}, r.builtinBeginHandlers...) |
| 208 | r.overlappedLink = next |
| 209 | } |
| 210 | |
| 211 | // APIBuilder the visible API for constructing the router |
| 212 | // and child routers. |
no test coverage detected
searching dependent graphs…