From b0a440b5d6a9f3c53a7602fd17929ebd37713eb5 Mon Sep 17 00:00:00 2001 From: perp Date: Mon, 3 Jun 2024 13:14:45 +0100 Subject: [PATCH] Handle API errors --- internal/context/context.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/context/context.go b/internal/context/context.go index e8ceb79..96b51d5 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -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, + } +}