Skip to content

Commit

Permalink
Add fiber error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
TomRomeo committed Mar 15, 2024
1 parent cb233c9 commit 40a438f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions backend/services/frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -75,6 +76,11 @@ func main() {

fiberConfig := fiber.Config{
ErrorHandler: func(ctx *fiber.Ctx, err error) error {
var e *fiber.Error
if errors.As(err, &e) {
logger.Infof("Fiber error %d with details (%s)!", e.Code, e.Error())
return ctx.Status(int(e.Code)).SendString(e.Error())
}
parsedError := microErrors.Parse(err.Error())
if parsedError.Code == 0 {
parsedError.Code = fiber.StatusInternalServerError
Expand Down

0 comments on commit 40a438f

Please sign in to comment.