diff --git a/api/server.go b/api/server.go index 2315ca0..3a764dc 100644 --- a/api/server.go +++ b/api/server.go @@ -18,7 +18,7 @@ func NewServer(resolver app.ResolveServiceInterface, admin app.AdminServiceInter return &Server{resolver: resolver, admin: admin, user: user} } -func (s *Server) Resolve(ctx *gin.Context) { +func (s *Server) Resolve(ctx *gin.Context) error { domain := ctx.Param("domain") name := ctx.Param("name") @@ -26,11 +26,11 @@ func (s *Server) Resolve(ctx *gin.Context) { switch true { case err == nil: ctx.Redirect(http.StatusFound, target) - return + return nil case errors.Is(err, app.ErrNotFound): respondWithError(ctx, http.StatusNotFound, err) - return + return nil default: - respondWithError(ctx, http.StatusInternalServerError, err) + return err } } diff --git a/api/server_routes.go b/api/server_routes.go index c0524db..4280007 100644 --- a/api/server_routes.go +++ b/api/server_routes.go @@ -30,7 +30,7 @@ func SetupRouting(r gin.IRouter, s *Server) { resolve.Use(validDomain, validName) - resolve.GET("/:domain/:name", s.Resolve) + resolve.GET("/:domain/:name", AsErrHandler(s.Resolve)) } // Admin endpoints