aboutsummaryrefslogtreecommitdiff
path: root/errors.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2018-03-08 22:36:04 +0100
committerStefan Majewsky <majewsky@gmx.net>2018-03-08 22:36:04 +0100
commit0a9bb149419c4df0be820f2cb72c8cc7e3332c68 (patch)
tree0584056dedcb673eeb8541c9a57aebee2c9bd7fa /errors.go
parentbded7c64d485ce5aaf82982573a041314257b4dc (diff)
downloadgo-schwift-0a9bb149419c4df0be820f2cb72c8cc7e3332c68.tar.gz
add Account.BulkUpload(), BulkUploadError, BulkObjectError
Diffstat (limited to 'errors.go')
-rw-r--r--errors.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/errors.go b/errors.go
index 0aa7acc..3ce7cd0 100644
--- a/errors.go
+++ b/errors.go
@@ -36,6 +36,9 @@ var (
//ErrMalformedContainerName is returned by Request.Do() if ContainerName
//contains slashes.
ErrMalformedContainerName = errors.New("container name may not contain slashes")
+ //ErrNotSupported is returned by bulk operations, large object operations,
+ //etc. if the server does not support the requested operation.
+ ErrNotSupported = errors.New("operation not supported by this Swift server")
)
//UnexpectedStatusCodeError is generated when a request to Swift does not yield
@@ -62,6 +65,50 @@ func (e UnexpectedStatusCodeError) Error() string {
return msg
}
+//BulkObjectError is the error message for a single object in a bulk operation.
+//It is not generated individually, only as part of BulkUploadError and BulkDeleteError.
+type BulkObjectError struct {
+ ContainerName string
+ ObjectName string
+ StatusCode int
+}
+
+//Error implements the builtin/error interface.
+func (e BulkObjectError) Error() string {
+ return fmt.Sprintf("%s/%s: %d %s",
+ e.ContainerName, e.ObjectName,
+ e.StatusCode, http.StatusText(e.StatusCode),
+ )
+}
+
+//BulkUploadError is returned by Account.BulkUpload() when the archive was
+//uploaded and unpacked successfully, but some (or all) files could not be
+//saved in Swift.
+type BulkUploadError struct {
+ //StatusCode contains the overall HTTP status code of the operation.
+ StatusCode int
+ //ArchiveError contains the error that occurred while unpacking the archive,
+ //or if the archive as a whole was not acceptable. If may be empty if no
+ //error occurred at this point.
+ ArchiveError string
+ //ObjectErrors contains errors that occurred while trying to save an
+ //individual file from the archive. It may be empty.
+ ObjectErrors []BulkObjectError
+}
+
+//Error implements the builtin/error interface. To fit into one line, it
+//condenses the ObjectErrors into a count.
+func (e BulkUploadError) Error() string {
+ result := fmt.Sprintf("%d %s", e.StatusCode, http.StatusText(e.StatusCode))
+ if e.ArchiveError != "" {
+ result += ": " + e.ArchiveError
+ }
+ if len(e.ObjectErrors) > 0 {
+ result += fmt.Sprintf(" (+%d object errors)", len(e.ObjectErrors))
+ }
+ return result
+}
+
//Is checks if the given error is an UnexpectedStatusCodeError for that status
//code. For example:
//