Skip to content

Commit

Permalink
Use custom err handler
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiante committed Oct 20, 2024
1 parent d78018c commit c1463cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ 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")

target, err := s.resolver.Resolve(domain, name)
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
}
}
2 changes: 1 addition & 1 deletion api/server_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c1463cb

Please sign in to comment.