Handle API errors
This commit is contained in:
parent
46d5f27409
commit
b0a440b5d6
@ -17,6 +17,7 @@ package context
|
|||||||
import (
|
import (
|
||||||
"git.supernets.org/perp/gopay/internal/config"
|
"git.supernets.org/perp/gopay/internal/config"
|
||||||
"git.supernets.org/perp/gopay/internal/database"
|
"git.supernets.org/perp/gopay/internal/database"
|
||||||
|
"git.supernets.org/perp/gopay/internal/models"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ func New(cfg *config.Config, db *database.Database) *Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle gin route with context
|
// Return a Gin Context
|
||||||
func (ctx *Context) API(handler func(ctx *Context)) func(*gin.Context) {
|
func (ctx *Context) API(handler func(ctx *Context)) func(*gin.Context) {
|
||||||
return func(gctx *gin.Context) {
|
return func(gctx *gin.Context) {
|
||||||
context := Context{
|
context := Context{
|
||||||
@ -57,3 +58,10 @@ func (ctx *Context) API(handler func(ctx *Context)) func(*gin.Context) {
|
|||||||
handler(&context)
|
handler(&context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return an Error
|
||||||
|
func (ctx *Context) Error(err string) models.Error {
|
||||||
|
return models.Error{
|
||||||
|
Type: err,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user