Handle API errors

This commit is contained in:
perp 2024-06-03 13:14:45 +01:00
parent 46d5f27409
commit b0a440b5d6

View File

@ -17,6 +17,7 @@ package context
import (
"git.supernets.org/perp/gopay/internal/config"
"git.supernets.org/perp/gopay/internal/database"
"git.supernets.org/perp/gopay/internal/models"
"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) {
return func(gctx *gin.Context) {
context := Context{
@ -57,3 +58,10 @@ func (ctx *Context) API(handler func(ctx *Context)) func(*gin.Context) {
handler(&context)
}
}
// Return an Error
func (ctx *Context) Error(err string) models.Error {
return models.Error{
Type: err,
}
}