Skip to content

Commit

Permalink
Merge pull request #80 from Maker-Management-Platform/69-bug---creati…
Browse files Browse the repository at this point in the history
…ng-an-empty-project-throws-a-400-error

Improved Error messages
  • Loading branch information
EduardoOliveira authored Jan 23, 2024
2 parents 1032ba6 + b1821af commit 35ba138
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 35ba138

Please sign in to comment.