Skip to content

Commit

Permalink
appprovider: support other error types, in particular AlreadyExists
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Aug 1, 2023
1 parent 156e727 commit b9a8ce6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ description: >
# _struct: config_

{{% dir name="mime_types" type="[]string" default=nil %}}
A list of mime types supported by this app. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L69)
A list of mime types supported by this app. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L68)
{{< highlight toml >}}
[grpc.services.appprovider]
mime_types = nil
{{< /highlight >}}
{{% /dir %}}

{{% dir name="custom_mime_types_json" type="string" default="nil" %}}
An optional mapping file with the list of supported custom file extensions and corresponding mime types. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L70)
An optional mapping file with the list of supported custom file extensions and corresponding mime types. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L69)
{{< highlight toml >}}
[grpc.services.appprovider]
custom_mime_types_json = "nil"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: >
# _struct: Config_

{{% dir name="insecure" type="bool" default=false %}}
Whether to skip certificate checks when sending requests. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/http/services/archiver/handler.go#L62)
Whether to skip certificate checks when sending requests. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/http/services/archiver/handler.go#L63)
{{< highlight toml >}}
[http.services.archiver]
insecure = false
Expand Down
3 changes: 1 addition & 2 deletions internal/grpc/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package appprovider
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"strconv"
Expand Down Expand Up @@ -211,7 +210,7 @@ func (s *service) OpenInApp(ctx context.Context, req *providerpb.OpenInAppReques
appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken, req.Opaque.Map, s.conf.Language)
if err != nil {
res := &providerpb.OpenInAppResponse{
Status: status.NewInternal(ctx, errors.New("appprovider: error calling GetAppURL"), err.Error()),
Status: status.NewStatusFromErrType(ctx, "appprovider: error calling GetAppURL", err),
}
return res, nil
}
Expand Down
4 changes: 4 additions & 0 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
writeError(w, r, appErrorNotFound, openRes.Status.Message, nil)
return
}
if openRes.Status.Code == rpc.Code_CODE_ALREADY_EXISTS {
writeError(w, r, appErrorAlreadyExists, openRes.Status.Message, nil)
return
}
writeError(w, r, appErrorServerError, openRes.Status.Message,
status.NewErrorFromCode(openRes.Status.Code, "error calling OpenInApp"))
return
Expand Down
6 changes: 3 additions & 3 deletions pkg/errtypes/errtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// and error is a reserved word :)
package errtypes

// NotFound is the error to use when a something is not found.
// NotFound is the error to use when something is not found.
type NotFound string

func (e NotFound) Error() string { return "error: not found: " + string(e) }
Expand All @@ -46,15 +46,15 @@ func (e PermissionDenied) Error() string { return "error: permission denied: " +
// IsPermissionDenied implements the IsPermissionDenied interface.
func (e PermissionDenied) IsPermissionDenied() {}

// AlreadyExists is the error to use when a resource something is not found.
// AlreadyExists is the error to use when a resource already exists and can't be overwritten.
type AlreadyExists string

func (e AlreadyExists) Error() string { return "error: already exists: " + string(e) }

// IsAlreadyExists implements the IsAlreadyExists interface.
func (e AlreadyExists) IsAlreadyExists() {}

// UserRequired represents an error when a resource is not found.
// UserRequired represents an error when a user could not be found from the context.
type UserRequired string

func (e UserRequired) Error() string { return "error: user required: " + string(e) }
Expand Down
2 changes: 2 additions & 0 deletions pkg/rgrpc/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ func NewStatusFromErrType(ctx context.Context, msg string, err error) *rpc.Statu
return NewUnimplemented(ctx, err, "gateway: "+msg+":"+err.Error())
case errtypes.BadRequest:
return NewInvalidArg(ctx, "gateway: "+msg+":"+err.Error())
case errtypes.AlreadyExists:
return NewAlreadyExists(ctx, err, "gateway: "+msg+":"+err.Error())
}

// map GRPC status codes coming from the auth middleware
Expand Down

0 comments on commit b9a8ce6

Please sign in to comment.