Skip to content

Commit 0d445f1

Browse files
committed
fiber: error handling for list and get endpoints
1 parent 581631a commit 0d445f1

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Additionaly, some examples with:
5757

5858
| Feature | gin | echo | iris | fiber | micro | goa | gorilla |
5959
|----------------------------------------------------| --- | ---- | ---- | ----- | ----- | --- | ------- |
60-
| Final Project Structure || ||||||
60+
| Final Project Structure || 👷🏼‍♂️ ||||||
6161
| "Hello, World!" and simple JSON response ||||||||
6262
| CRUD JSON API for [the example entity][folder-pkg] |||| 👷🏼‍♂️ ||||
6363
| Paging and error handling ||||||||

fiber/server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func main() {
3535
// c.JSON(pkg.TextResponse{Message: err.Error()})
3636
// return fiber.NewError(fiber.StatusInternalServerError, err.Error())
3737

38+
// TODO: Replace 500 error with 4xx for paging related errors.
3839
errMsg := pkg.TextResponse{Message: err.Error()}
3940
return c.Status(fiber.StatusInternalServerError).JSON(errMsg)
4041
}
@@ -47,8 +48,8 @@ func main() {
4748

4849
entity, err := entitiesRepo.Get(entityID)
4950
if err != nil {
50-
c.JSON(pkg.TextResponse{Message: err.Error()})
51-
return fiber.ErrInternalServerError
51+
errMsg := pkg.TextResponse{Message: err.Error()}
52+
return c.Status(fiber.StatusInternalServerError).JSON(errMsg)
5253
}
5354

5455
if entity == nil {

0 commit comments

Comments
 (0)