Skip to content

Commit

Permalink
Improved Error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoOliveira committed Jan 23, 2024
1 parent ff4f94f commit b1821af
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/projects/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,27 @@ func new(c echo.Context) error {
form, err := c.MultipartForm()
if err != nil {
log.Println(err)
return c.NoContent(http.StatusBadRequest)
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}

files := form.File["files"]

if len(files) == 0 {
log.Println("No files")
return c.NoContent(http.StatusBadRequest)
return echo.NewHTTPError(http.StatusBadRequest, errors.New("no files uploaded").Error())
}

projectPayload := form.Value["payload"]
if len(projectPayload) != 1 {
log.Println("more payloads than expected")
return c.NoContent(http.StatusBadRequest)
return echo.NewHTTPError(http.StatusBadRequest, errors.New("more payloads than expected").Error())
}

createProject := &CreateProject{}
err = json.Unmarshal([]byte(projectPayload[0]), createProject)
if err != nil {
log.Println(err)
return c.NoContent(http.StatusBadRequest)
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}

project := models.NewProject()
Expand Down Expand Up @@ -258,7 +258,7 @@ func new(c echo.Context) error {
ok, assets, err := discovery.DiscoverProject(project)
if err != nil {
log.Printf("error loading the project %q: %v\n", path, err)
return err
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
if !ok {
err = errors.New("failed to find assets")
Expand Down

0 comments on commit b1821af

Please sign in to comment.