Permalink
Browse files

Break out to external errors rather than per-service

  • Loading branch information...
1 parent 7873a84 commit cd1f2032c63f6e534b5d0ebfebb254a7cd79b2e1 James D. Nurmi committed Jun 21, 2011
Showing with 29 additions and 27 deletions.
  1. +21 −0 consts.go
  2. +5 −5 s3/bucket_opers.go
  3. +0 −19 s3/consts.go
  4. +3 −3 s3/service_opers.go
View
@@ -1,8 +1,29 @@
package aws
+import (
+ "os"
+ "http"
+)
+
const (
DEFAULT_SIGNATURE_VERSION = "2"
DEFAULT_SIGNATURE_METHOD = "HmacSHA256"
)
+var ErrorNotFound os.Error = os.NewError("Not found")
+var ErrorUnexpectedResponse os.Error = os.NewError("Unexpected response code")
+var ErrorConflicts os.Error = os.NewError("Conflicts with another resources")
+var ErrorForbidden os.Error = os.NewError("Access denied")
+
+func CodeToError(i int)(err os.Error){
+ switch i {
+ case http.StatusOK:
+ case http.StatusNotFound: err = ErrorNotFound
+ case http.StatusConflict: err = ErrorConflicts
+ case http.StatusForbidden: err = ErrorForbidden
+ default: err = ErrorUnexpectedResponse
+ }
+ return
+}
+
View
@@ -66,7 +66,7 @@ func (self *Bucket)PutFile(id *aws.Signer, key string, fp *os.File)(err os.Error
err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15)
if err == nil {
resp, err = self.conn.Request(hreq)
- if err == nil { err = CodeToError(resp.StatusCode) }
+ if err == nil { err = aws.CodeToError(resp.StatusCode) }
}
}
return
@@ -84,7 +84,7 @@ func (self *Bucket)Delete(id *aws.Signer, key string)(err os.Error){
}
if err == nil {
if resp.StatusCode != http.StatusNoContent {
- err = CodeToError(resp.StatusCode)
+ err = aws.CodeToError(resp.StatusCode)
}
}
@@ -99,7 +99,7 @@ func (self *Bucket)GetKey(id *aws.Signer, key string, w io.Writer)(http.Header,
resp, err = self.conn.Request(hreq)
}
if err == nil {
- err = CodeToError(resp.StatusCode)
+ err = aws.CodeToError(resp.StatusCode)
}
if resp != nil {
@@ -117,7 +117,7 @@ func (self *Bucket)Exists(id *aws.Signer, key string)(err os.Error){
resp, err = self.conn.Request(hreq)
}
if err == nil {
- err = CodeToError(resp.StatusCode)
+ err = aws.CodeToError(resp.StatusCode)
}
return
}
@@ -147,7 +147,7 @@ func (self *Bucket)ListKeys(id *aws.Signer,
resp, err = self.conn.Request(hreq)
}
if err == nil {
- err = CodeToError(resp.StatusCode)
+ err = aws.CodeToError(resp.StatusCode)
}
if err == nil {
err = xml.Unmarshal(resp.Body, &result)
View
@@ -2,8 +2,6 @@ package s3
import (
"crypto"
- "http"
- "os"
)
@@ -20,20 +18,3 @@ const (
)
-var ErrorUnknownKey os.Error = os.NewError("Unknown Key")
-var ErrorUnexpectedResponse os.Error = os.NewError("Unexpected response code")
-var ErrorConflicts os.Error = os.NewError("Conflicts with anothers resources")
-var ErrorPermissions os.Error = os.NewError("Access denied")
-
-func CodeToError(i int)(err os.Error){
- switch i {
- case http.StatusOK:
- case http.StatusNotFound: err = ErrorUnknownKey
- case http.StatusConflict: err = ErrorConflicts
- case http.StatusForbidden: err = ErrorPermissions
- default: err = ErrorUnexpectedResponse
- }
- return
-}
-
-
View
@@ -52,7 +52,7 @@ func (self *Service)DeleteBucket(id *aws.Signer, name string)(err os.Error){
if err == nil {
if resp.StatusCode != http.StatusNoContent {
- err = CodeToError(resp.StatusCode)
+ err = aws.CodeToError(resp.StatusCode)
}
}
@@ -68,7 +68,7 @@ func (self *Service)CreateBucket(id *aws.Signer, name string)(err os.Error){
resp, err = self.conn.Request(hreq)
}
if err == nil {
- err = CodeToError(resp.StatusCode)
+ err = aws.CodeToError(resp.StatusCode)
}
return
}
@@ -84,7 +84,7 @@ func (self *Service)ListBuckets(id *aws.Signer)(out []string, err os.Error){
resp, err = self.conn.Request(hreq)
}
if err == nil {
- err = CodeToError(resp.StatusCode)
+ err = aws.CodeToError(resp.StatusCode)
}
if err == nil {
result := listAllMyBucketsResult{}

0 comments on commit cd1f203

Please sign in to comment.