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

Move OCS error handlers to pkg #593

Closed
wants to merge 2 commits into from

Conversation

ishank011
Copy link
Contributor

No description provided.

// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package errhandler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice abstraction! however, I think the chose of name is incorrect, and the base principles. While an errhandler package would allow for abstracting error handling, this package deals more with OCS messages.

On my mind working with interfaces is more appropriate as a generalized idea of error handling, then, every package that deals with the ocs api would implement the errhandler interface. Otherwise if you want to keep this generic, more functions will be added for different packages.

Copy link
Contributor Author

@ishank011 ishank011 Mar 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @refs, thanks for the review! The main idea behind moving this to pkg was to prevent implementing it again. We're currently implementing the OCM HTTP service and it would have the same error codes as these, and I imagine all HTTP services would be having these, and the fact that we could pass messages to add details makes these quite generic. But we could definitely change the package name to signify that it handles HTTP error codes.

Please let me know if that would be fine. And any suggestions that you have for the package name 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishank011 are really the OCS error responses the same for OCM? The ones that I've found in OCM only have a "MESSAGE" field:

{
  "message": "RESOURCE_NOT_FOUND"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@labkode OCM defines it's own error codes and a few associated methods in https://github.com/cernbox/ocmd/blob/master/api/api.go#L14 which match with the OCS erros (https://github.com/cs3org/reva/blob/master/internal/http/services/owncloud/ocs/reqres.go#L54). We can add more if required. So instead of having separate implementations in both the services, this way we can just use a common package.

So what was previously done as https://github.com/cernbox/ocmd/blob/master/handlers/handlers.go#L308

ae := api.NewAPIError(api.APIErrorInvalidParameter).WithMessage("body is not json")
w.Write(ae.JSON())

can now be done in a similar way as OCS does.

errhandler.WriteError(w, r, MetaBadRequest.StatusCode, "body is not json"", nil)

@butonic
Copy link
Contributor

butonic commented Mar 23, 2020

The OCS errors need a better implementation, because there is a difference between the OCS v1 Vs V2 http status code handling. We need to respond with different codes, depending on the endpoint. Tracked in owncloud/ocis-reva#26

@butonic
Copy link
Contributor

butonic commented Mar 24, 2020

The TODO is right above the mapping code: https://github.com/cs3org/reva/blob/master/internal/http/services/owncloud/ocs/reqres.go#L117-L138

It is derived from owncloud/core@bacf160#diff-c1d6f3585e52926be0ec6169c0f58c38R442-R466

However, it is only necessary for the v2 endpoint.

This ties the mapping to the endpoint. 🤷‍♂️

We can pass a boolean isV2 flag (shudder) or a mapper function as a new parameter (meh) which clutters up the handler signatures. In this case the context might be the right place. Then the ocs handler can store the error mapper function in the context and the error handler can check if the context has a mapper function. If you feel this does not make functionality obvious enough we could also store the mapper function or a preconfigure error handler in the handler when setting up the v1 and v2 handlers.

Copy link
Contributor

@butonic butonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am leaning towards adding a mapper function to the handlers. But maybe the OCM implementation has requirements that clarify how we should implement it.
opinions?

@refs
Copy link
Member

refs commented Mar 24, 2020

I am leaning towards adding a mapper function to the handlers. But maybe the OCM implementation has requirements that clarify how we should implement it.
opinions?

My two cents: Agree with the implementation details, but my point on an untied, abstract, cold interface definition that's not tied to the OCS API still stands. Do the OCM messages care about OCS meta statuses? Because this implementation requires just that. Or at least is not reflecting a more general approach

@labkode
Copy link
Member

labkode commented Mar 24, 2020

@ishank011 for time being we leave the OCS on one side and the OCM on other. These two services will evolve independently. OCS and OCDAV at some point will be moved to the OCIS repo while OCM will continue to live in Reva.

@ishank011
Copy link
Contributor Author

@labkode Okay, will close this and add a similar implementation for OCM. Thanks all for the reviews!

@ishank011 ishank011 closed this Mar 24, 2020
@ishank011 ishank011 deleted the errhandler_pkg branch March 24, 2020 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants