1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00

Path type parameter error handler: add the parameter index in the input arguments

see previous commit
This commit is contained in:
Gerasimos (Makis) Maropoulos
2021-02-15 11:30:29 +02:00
parent 5990e7f432
commit e901575ca8
5 changed files with 19 additions and 12 deletions

View File

@@ -153,11 +153,15 @@ func main() {
// UUIDv4 (and v1) path parameter validation.
// Optionally, set custom handler on path parameter type error:
app.Macros().Get("uuid").HandleError(func(ctx iris.Context, err error) {
app.Macros().Get("uuid").HandleError(func(ctx iris.Context, paramIndex int, err error) {
ctx.StatusCode(iris.StatusBadRequest)
param := ctx.Params().GetEntryAt(paramIndex)
ctx.JSON(iris.Map{
"error": err.Error(),
"message": "invalid path parameter",
"error": err.Error(),
"message": "invalid path parameter",
"parameter": param.Key,
"value": param.ValueRaw,
})
})