Skip to content

Commit

Permalink
Report errors thrown by the WOPI servers
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Sep 24, 2021
1 parent b7dcd27 commit d370af7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/app-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: propagate back errors reported by the WOPI server on open

https://github.com/cs3org/reva/pull/2103
3 changes: 1 addition & 2 deletions internal/grpc/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ func getProvider(c *config) (app.Provider, error) {
func (s *service) OpenInApp(ctx context.Context, req *providerpb.OpenInAppRequest) (*providerpb.OpenInAppResponse, error) {
appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken)
if err != nil {
err := errors.Wrap(err, "appprovider: error calling GetAppURL")
res := &providerpb.OpenInAppResponse{
Status: status.NewInternal(ctx, err, "error getting app URL"),
Status: status.NewInternal(ctx, errors.Wrap(err, "appprovider: error calling GetAppURL"), err.Error()),
}
return res, nil
}
Expand Down
5 changes: 3 additions & 2 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,13 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
}
openRes, err := client.OpenInApp(ctx, &openReq)
if err != nil {
ocmd.WriteError(w, r, ocmd.APIErrorServerError, "error opening resource", err)
log.Error().Err(err).Msg("error calling OpenInApp")
ocmd.WriteError(w, r, ocmd.APIErrorServerError, err.Error(), err)
return
}
if openRes.Status.Code != rpc.Code_CODE_OK {
ocmd.WriteError(w, r, ocmd.APIErrorServerError, "error opening resource information",
status.NewErrorFromCode(openRes.Status.Code, "appprovider"))
status.NewErrorFromCode(openRes.Status.Code, openRes.Status.Message))
return
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/app/provider/wopi/wopi.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,16 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc
}
defer openRes.Body.Close()

if openRes.StatusCode != http.StatusOK {
return nil, errtypes.InternalError("wopi: unexpected status from WOPI server: " + openRes.Status)
}

body, err := ioutil.ReadAll(openRes.Body)
if err != nil {
return nil, err
}

if openRes.StatusCode != http.StatusOK {
log.Warn().Msg(fmt.Sprintf("wopi: WOPI server returned HTTP %s, error was: %s", openRes.Status, body))
return nil, errtypes.InternalError(body)
}

var result map[string]interface{}
err = json.Unmarshal(body, &result)
if err != nil {
Expand Down

0 comments on commit d370af7

Please sign in to comment.