1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-21 11:57:02 +00:00

overlap routing: and mvc: allow setting status code from a dependency or a middleware

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-08-28 04:11:56 +03:00
parent 933534574a
commit a6ec94e1a6
10 changed files with 181 additions and 63 deletions

View File

@@ -1,7 +1,7 @@
package versioning
import (
"errors"
"fmt"
"strings"
"github.com/kataras/iris/v12/context"
@@ -34,7 +34,7 @@ const (
// ErrNotFound reports whether a requested version
// does not match with any of the server's implemented ones.
var ErrNotFound = errors.New("version not found")
var ErrNotFound = fmt.Errorf("version %w", context.ErrNotFound)
// NotFoundHandler is the default version not found handler that
// is executed from `NewMatcher` when no version is registered as available to dispatch a resource.

View File

@@ -49,9 +49,11 @@ func Match(ctx *context.Context, expectedVersion string) bool {
func Handler(version string) context.Handler {
return func(ctx *context.Context) {
if !Match(ctx, version) {
// Any overlapped handler
// can just clear the status code
// and the error to ignore this (see `NewGroup`).
// The overlapped handler has an exception
// of a type of context.NotFound (which versioning.ErrNotFound wraps)
// to clear the status code
// and the error to ignore this
// when available match version exists (see `NewGroup`).
NotFoundHandler(ctx)
return
}