mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2024-11-26 22:20:18 +01:00
Wrap Errors and rename class
This commit is contained in:
parent
1e815d382c
commit
5bb0e84fa5
1 changed files with 9 additions and 9 deletions
|
@ -565,7 +565,7 @@ func saveGDriveToken(path string, token *oauth2.Token, logger *log.Logger) {
|
|||
json.NewEncoder(f).Encode(token)
|
||||
}
|
||||
|
||||
var uplinkFailure = errs.Class("uplink failure")
|
||||
var uplinkFailure = errs.Class("storj failure")
|
||||
|
||||
type StorjStorage struct {
|
||||
Storage
|
||||
|
@ -583,29 +583,29 @@ func NewStorjStorage(endpoint, apiKey, bucket, encKey string, logger *log.Logger
|
|||
|
||||
instance.uplink, err = uplink.NewUplink(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, uplinkFailure.New("could not create new Uplink Instance: %v", err)
|
||||
return nil, uplinkFailure.Wrap(err)
|
||||
}
|
||||
|
||||
key, err := uplink.ParseAPIKey(apiKey)
|
||||
if err != nil {
|
||||
return nil, uplinkFailure.New("could not parse api key: %v", err)
|
||||
return nil, uplinkFailure.Wrap(err)
|
||||
}
|
||||
|
||||
instance.project, err = instance.uplink.OpenProject(ctx, endpoint, key)
|
||||
if err != nil {
|
||||
return nil, uplinkFailure.New("could not open project: %v", err)
|
||||
return nil, uplinkFailure.Wrap(err)
|
||||
}
|
||||
|
||||
saltenckey, err := instance.project.SaltedKeyFromPassphrase(ctx, encKey)
|
||||
if err != nil {
|
||||
return nil, uplinkFailure.New("could not generate salted enc key: %v", err)
|
||||
return nil, uplinkFailure.Wrap(err)
|
||||
}
|
||||
|
||||
access := uplink.NewEncryptionAccessWithDefaultKey(*saltenckey)
|
||||
|
||||
instance.bucket, err = instance.project.OpenBucket(ctx, bucket, access)
|
||||
if err != nil {
|
||||
return nil, uplinkFailure.New("could not open bucket %q: %v", bucket, err)
|
||||
return nil, uplinkFailure.Wrap(err)
|
||||
}
|
||||
|
||||
instance.logger = logger
|
||||
|
@ -624,7 +624,7 @@ func (s *StorjStorage) Head(token string, filename string) (contentType string,
|
|||
|
||||
obj, err := s.bucket.OpenObject(ctx, key)
|
||||
if err != nil {
|
||||
return "", 0, fmt.Errorf("unable to open object %v", err)
|
||||
return "", 0, uplinkFailure.Wrap(err)
|
||||
}
|
||||
contentType = obj.Meta.ContentType
|
||||
contentLength = uint64(obj.Meta.Size)
|
||||
|
@ -641,7 +641,7 @@ func (s *StorjStorage) Get(token string, filename string) (reader io.ReadCloser,
|
|||
|
||||
obj, err := s.bucket.OpenObject(ctx, key)
|
||||
if err != nil {
|
||||
return nil, "", 0, uplinkFailure.New("unable to open object %v", err)
|
||||
return nil, "", 0, uplinkFailure.Wrap(err)
|
||||
}
|
||||
contentType = obj.Meta.ContentType
|
||||
contentLength = uint64(obj.Meta.Size)
|
||||
|
@ -670,7 +670,7 @@ func (s *StorjStorage) Put(token string, filename string, reader io.Reader, cont
|
|||
|
||||
err = s.bucket.UploadObject(ctx, key, reader, &uplink.UploadOptions{ContentType: contentType})
|
||||
if err != nil {
|
||||
return uplinkFailure.New("could not upload: %v", err)
|
||||
return uplinkFailure.Wrap(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue