Skip to content

Commit 8db8720

Browse files
committed
appprovider: support other error types, in particular AlreadyExists
1 parent 01aae16 commit 8db8720

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

docs/content/en/docs/config/grpc/services/appprovider/_index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ description: >
99
# _struct: config_
1010

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

1919
{{% dir name="custom_mime_types_json" type="string" default="nil" %}}
20-
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)
20+
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)
2121
{{< highlight toml >}}
2222
[grpc.services.appprovider]
2323
custom_mime_types_json = "nil"

docs/content/en/docs/config/http/services/archiver/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: >
99
# _struct: Config_
1010

1111
{{% dir name="insecure" type="bool" default=false %}}
12-
Whether to skip certificate checks when sending requests. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/http/services/archiver/handler.go#L62)
12+
Whether to skip certificate checks when sending requests. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/http/services/archiver/handler.go#L63)
1313
{{< highlight toml >}}
1414
[http.services.archiver]
1515
insecure = false

internal/grpc/services/appprovider/appprovider.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package appprovider
2121
import (
2222
"context"
2323
"encoding/json"
24-
"errors"
2524
"fmt"
2625
"os"
2726
"strconv"
@@ -211,7 +210,7 @@ func (s *service) OpenInApp(ctx context.Context, req *providerpb.OpenInAppReques
211210
appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken, req.Opaque.Map, s.conf.Language)
212211
if err != nil {
213212
res := &providerpb.OpenInAppResponse{
214-
Status: status.NewInternal(ctx, errors.New("appprovider: error calling GetAppURL"), err.Error()),
213+
Status: status.NewStatusFromErrType(ctx, "appprovider: error calling GetAppURL", err),
215214
}
216215
return res, nil
217216
}

internal/http/services/appprovider/appprovider.go

+4
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
408408
writeError(w, r, appErrorNotFound, openRes.Status.Message, nil)
409409
return
410410
}
411+
if openRes.Status.Code == rpc.Code_CODE_ALREADY_EXISTS {
412+
writeError(w, r, appErrorAlreadyExists, openRes.Status.Message, nil)
413+
return
414+
}
411415
writeError(w, r, appErrorServerError, openRes.Status.Message,
412416
status.NewErrorFromCode(openRes.Status.Code, "error calling OpenInApp"))
413417
return

pkg/errtypes/errtypes.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// and error is a reserved word :)
2323
package errtypes
2424

25-
// NotFound is the error to use when a something is not found.
25+
// NotFound is the error to use when something is not found.
2626
type NotFound string
2727

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

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

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

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

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

6060
func (e UserRequired) Error() string { return "error: user required: " + string(e) }

pkg/rgrpc/status/status.go

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ func NewStatusFromErrType(ctx context.Context, msg string, err error) *rpc.Statu
181181
return NewUnimplemented(ctx, err, "gateway: "+msg+":"+err.Error())
182182
case errtypes.BadRequest:
183183
return NewInvalidArg(ctx, "gateway: "+msg+":"+err.Error())
184+
case errtypes.AlreadyExists:
185+
return NewAlreadyExists(ctx, err, "gateway: "+msg+":"+err.Error())
184186
}
185187

186188
// map GRPC status codes coming from the auth middleware

0 commit comments

Comments
 (0)