Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return 404 code if file isn't found on CheckFileInfo request #10112

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/collaboration-fileinfo-error-code.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions services/collaboration/pkg/connector/fileconnector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 13 additions & 0 deletions services/collaboration/pkg/connector/fileconnector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down