Skip to content

Commit

Permalink
return 425 if you open a file in postprocessing with /app/open (#3385)
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek authored Oct 21, 2022
1 parent 0bdcf53 commit 613c284
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,17 @@ func (s *svc) handleOpen(openMode int) http.HandlerFunc {
Path: ".",
}

statRes, err := client.Stat(ctx, &provider.StatRequest{Ref: fileRef})
if err != nil {
writeError(w, r, appErrorServerError, "Internal error accessing the file, please try again later", err)
return
}

if status := utils.ReadPlainFromOpaque(statRes.Opaque, "status"); status == "processing" {
writeError(w, r, appErrorTooEarly, "The requested file is not yet available, please try again later", nil)
return
}

viewMode, err := getViewModeFromPublicScope(ctx)
if err != nil {
writeError(w, r, appErrorPermissionDenied, "permission denied to open the application", err)
Expand Down
2 changes: 2 additions & 0 deletions internal/http/services/appprovider/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
appErrorUnimplemented appErrorCode = "NOT_IMPLEMENTED"
appErrorInvalidParameter appErrorCode = "INVALID_PARAMETER"
appErrorServerError appErrorCode = "SERVER_ERROR"
appErrorTooEarly appErrorCode = "TOO_EARLY"
)

// appErrorCodeMapping stores the HTTP error code mapping for various APIErrorCodes
Expand All @@ -47,6 +48,7 @@ var appErrorCodeMapping = map[appErrorCode]int{
appErrorInvalidParameter: http.StatusBadRequest,
appErrorServerError: http.StatusInternalServerError,
appErrorPermissionDenied: http.StatusForbidden,
appErrorTooEarly: http.StatusTooEarly,
}

// APIError encompasses the error type and message
Expand Down

0 comments on commit 613c284

Please sign in to comment.