Better error handling

This commit is contained in:
Piotr Rogowski 2022-11-05 19:40:58 +01:00
parent cf77b3c59e
commit 56d9672ab5
No known key found for this signature in database
GPG Key ID: 4A842D702D9C6F8F
1 changed files with 3 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/models"
)
@ -21,7 +22,7 @@ func main() {
record, _err := app.Dao().FindFirstRecordByData("tunes", "tuneId", c.PathParam("tuneId"))
if _err != nil {
return c.JSON(http.StatusNotFound, _err)
return apis.NewNotFoundError("Tune not found", nil)
}
_errors := app.Dao().ExpandRecord(record, []string{"author"}, func(relCollection *models.Collection, relIds []string) ([]*models.Record, error) {
@ -31,7 +32,7 @@ func main() {
})
if len(_errors) > 0 {
return c.JSON(http.StatusNotFound, _errors)
return apis.NewNotFoundError("Author not found", nil)
}
return c.JSON(http.StatusOK, record)