@ -696,13 +696,19 @@ func (web *webAPIHandlers) SetBucketPolicy(r *http.Request, args *SetBucketPolic
err = parseBucketPolicy ( bytes . NewReader ( data ) , policy )
err = parseBucketPolicy ( bytes . NewReader ( data ) , policy )
if err != nil {
if err != nil {
errorIf ( err , "Unable to parse bucket policy." )
errorIf ( err , "Unable to parse bucket policy." )
return toJSONError ( err )
return toJSONError ( err , args . BucketName )
}
}
// Parse check bucket policy.
// Parse check bucket policy.
if s3Error := checkBucketPolicyResources ( args . BucketName , policy ) ; s3Error != ErrNone {
if s3Error := checkBucketPolicyResources ( args . BucketName , policy ) ; s3Error != ErrNone {
apiErr := getAPIError ( s3Error )
apiErr := getAPIError ( s3Error )
return toJSONError ( errors . New ( apiErr . Description ) , args . BucketName )
var err error
if apiErr . Code == "XMinioPolicyNesting" {
err = PolicyNesting { }
} else {
err = errors . New ( apiErr . Description )
}
return toJSONError ( err , args . BucketName )
}
}
// TODO: update policy statements according to bucket name,
// TODO: update policy statements according to bucket name,
@ -850,6 +856,8 @@ func toWebAPIError(err error) APIError {
apiErrCode = ErrStorageFull
apiErrCode = ErrStorageFull
case BucketNotFound :
case BucketNotFound :
apiErrCode = ErrNoSuchBucket
apiErrCode = ErrNoSuchBucket
case BucketExists :
apiErrCode = ErrBucketAlreadyOwnedByYou
case BucketNameInvalid :
case BucketNameInvalid :
apiErrCode = ErrInvalidBucketName
apiErrCode = ErrInvalidBucketName
case BadDigest :
case BadDigest :
@ -866,7 +874,11 @@ func toWebAPIError(err error) APIError {
apiErrCode = ErrWriteQuorum
apiErrCode = ErrWriteQuorum
case InsufficientReadQuorum :
case InsufficientReadQuorum :
apiErrCode = ErrReadQuorum
apiErrCode = ErrReadQuorum
case PolicyNesting :
apiErrCode = ErrPolicyNesting
default :
default :
// Log unexpected and unhandled errors.
errorIf ( err , errUnexpected . Error ( ) )
apiErrCode = ErrInternalError
apiErrCode = ErrInternalError
}
}
apiErr := getAPIError ( apiErrCode )
apiErr := getAPIError ( apiErrCode )