閱讀154 返回首頁    go 阿裏雲


錯誤__Go-SDK_SDK 參考_對象存儲 OSS-阿裏雲

Go中調用出錯,會統一返回接口error,該接口定義如下:

    type error interface {
        Error() string
    }

其它的錯誤繼承於該接口。比如HTTP錯誤請求返回的錯誤如下:

    //net.Error 
    type Error interface {
        error
        Timeout() bool   // Is the error a timeout
        Temporary() bool // Is the error temporary
    }

使用OSS Go SDK時如果請求出錯,會有相應的error返回。HTTP請求、IO等錯誤會返回Go預定的錯誤。 OSS Server處理請求出錯,返回如下的錯誤,該錯誤實現了error接口。

    type ServiceError struct {
        Code       string    // OSS返回給用戶的錯誤碼
        Message    string    // OSS給出的詳細錯誤信息
        RequestId  string    // 用於唯一標識該次請求的UUID
        HostId     string    // 用於標識訪問的OSS集群
        StatusCode int       // HTTP狀態碼
    }

如果OSS返回的HTTP狀態碼與預期不符返回如下錯誤,該錯誤也實現了error接口。

    type UnexpectedStatusCodeError struct {
        allowed []int    // 預期OSS返回HTTP狀態碼
        got     int      // OSS實際返回HTTP狀態碼
    }

OSS的錯誤碼

OSS的錯誤碼列表如下:

錯誤碼 描述 HTTP狀態碼
AccessDenied 拒絕訪問 403
BucketAlreadyExists Bucket已經存在 409
BucketNotEmpty Bucket不為空 409
EntityTooLarge 實體過大 400
EntityTooSmall 實體過小 400
FileGroupTooLarge 文件組過大 400
InvalidLinkName Object Link與指向的Object同名 400
LinkPartNotExist Object Link中指向的Object不存在 400
ObjectLinkTooLarge Object Link中Object個數過多 400
FieldItemTooLong Post請求中表單域過大 400
FilePartInterity 文件Part已改變 400
FilePartNotExist 文件Part不存在 400
FilePartStale 文件Part過時 400
IncorrectNumberOfFilesInPOSTRequest Post請求中文件個數非法 400
InvalidArgument 參數格式錯誤 400
InvalidAccessKeyId AccessKeyId不存在 403
InvalidBucketName 無效的Bucket名字 400
InvalidDigest 無效的摘要 400
InvalidEncryptionAlgorithmError 指定的熵編碼加密算法錯誤 400
InvalidObjectName 無效的Object名字 400
InvalidPart 無效的Part 400
InvalidPartOrder 無效的part順序 400
InvalidPolicyDocument 無效的Policy文檔 400
InvalidTargetBucketForLogging Logging操作中有無效的目標bucket 400
InternalError OSS內部發生錯誤 500
MalformedXML XML格式非法 400
MalformedPOSTRequest Post請求的body格式非法 400
MaxPOSTPreDataLengthExceededError Post請求上傳文件內容之外的body過大 400
MethodNotAllowed 不支持的方法 405
MissingArgument 缺少參數 411
MissingContentLength 缺少內容長度 411
NoSuchBucket Bucket不存在 404
NoSuchKey 文件不存在 404
NoSuchUpload Multipart Upload ID不存在 404
NotImplemented 無法處理的方法 501
PreconditionFailed 預處理錯誤 412
RequestTimeTooSkewed 發起請求的時間和服務器時間超出15分鍾 403
RequestTimeout 請求超時 400
RequestIsNotMultiPartContent Post請求content-type非法 400
SignatureDoesNotMatch 簽名錯誤 403
TooManyBuckets 用戶的Bucket數目超過限製 400
InvalidEncryptionAlgorithmError 指定的熵編碼加密算法錯誤 400

提示:

  • 上表的錯誤碼即OssServiceError.Code,HTTP狀態碼即OssServiceError.StatusCode。
  • 如果試圖以OSS不支持的操作來訪問某個資源,返回405 Method Not Allowed錯誤。

最後更新:2016-11-23 17:16:08

  上一篇:go 設置跨域資源共享__Ruby-SDK_SDK 參考_對象存儲 OSS-阿裏雲
  下一篇:go 服務端__Media-C-SDK_SDK 參考_對象存儲 OSS-阿裏雲