Skip to content

Commit

Permalink
Fix bad error check in rest endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulFarver committed Feb 22, 2022
1 parent e19deed commit a022b88
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions internal/rest/v1/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ func (h *Handlers) getProjectLanguage(ctx echo.Context, l *logrus.Entry) error {
return echo.NewHTTPError(499, "client closed request")
}

if ctx.Request() == nil {
l.Error("Request is nil")

return errors.New("request is nil")
}

if ctx.Request().Header.Get("If-None-Match") == trans.Checksum {
return ctx.NoContent(http.StatusNotModified)
}

if err != nil {
switch err.(type) {
case *poedit.ErrProjectPermissionDenied:
Expand All @@ -83,6 +73,16 @@ func (h *Handlers) getProjectLanguage(ctx echo.Context, l *logrus.Entry) error {
}
}

if ctx.Request() == nil {
l.Error("Request is nil")

return errors.New("request is nil")
}

if ctx.Request().Header.Get("If-None-Match") == trans.Checksum {
return ctx.NoContent(http.StatusNotModified)
}

ctx.Response().Header().Add("Etag", trans.Checksum)
ctx.Response().Header().Add("Cache-Control", fmt.Sprintf("max-age=%.0f", trans.TTL.Seconds()))
ctx.Response().Header().Add("Content-Disposition", fmt.Sprintf("filename=%d-%s.%s", req.Project, req.Language, contentMeta.Extension))
Expand Down

0 comments on commit a022b88

Please sign in to comment.