diff --git a/changelog/unreleased/collaboration-fileinfo-error-code.md b/changelog/unreleased/collaboration-fileinfo-error-code.md new file mode 100644 index 00000000000..f76ac0b1605 --- /dev/null +++ b/changelog/unreleased/collaboration-fileinfo-error-code.md @@ -0,0 +1,5 @@ +Bugfix: CheckFileInfo will return a 404 error if the target file isn't found + +Previously, the request failed with a 500 error code, but it it will fail with a 404 error code + +https://github.com/owncloud/ocis/pull/10112 diff --git a/services/collaboration/pkg/connector/fileconnector.go b/services/collaboration/pkg/connector/fileconnector.go index a934fb5f2e5..ab4121956ed 100644 --- a/services/collaboration/pkg/connector/fileconnector.go +++ b/services/collaboration/pkg/connector/fileconnector.go @@ -1058,6 +1058,10 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (*ConnectorResponse, Str("StatusCode", statRes.GetStatus().GetCode().String()). Str("StatusMsg", statRes.GetStatus().GetMessage()). Msg("CheckFileInfo: stat failed with unexpected status") + + if statRes.GetStatus().GetCode() == rpcv1beta1.Code_CODE_NOT_FOUND { + return NewResponse(404), nil + } return NewResponse(500), nil } diff --git a/services/collaboration/pkg/connector/fileconnector_test.go b/services/collaboration/pkg/connector/fileconnector_test.go index 8dfa4961f57..e676ea17421 100644 --- a/services/collaboration/pkg/connector/fileconnector_test.go +++ b/services/collaboration/pkg/connector/fileconnector_test.go @@ -1634,6 +1634,19 @@ var _ = Describe("FileConnector", func() { Expect(response.Body).To(BeNil()) }) + It("Stat fails status not found", func() { + ctx := middleware.WopiContextToCtx(context.Background(), wopiCtx) + + gatewayClient.On("Stat", mock.Anything, mock.Anything).Times(1).Return(&providerv1beta1.StatResponse{ + Status: status.NewNotFound(ctx, "something not found"), + }, nil) + + response, err := fc.CheckFileInfo(ctx) + Expect(err).ToNot(HaveOccurred()) + Expect(response.Status).To(Equal(404)) + Expect(response.Body).To(BeNil()) + }) + It("Stat success", func() { ctx := middleware.WopiContextToCtx(context.Background(), wopiCtx) u := &userv1beta1.User{