1 /*
2 * Copyright 2017 Baidu, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11 * either express or implied. See the License for the specific language governing permissions
12 * and limitations under the License.
13 */
14 15 // error.go - define the error types for BCE
16 17 package bce
18 19 const (
20 EACCESS_DENIED = "AccessDenied"
21 EINAPPROPRIATE_JSON = "InappropriateJSON"
22 EINTERNAL_ERROR = "InternalError"
23 EINVALID_ACCESS_KEY_ID = "InvalidAccessKeyId"
24 EINVALID_HTTP_AUTH_HEADER = "InvalidHTTPAuthHeader"
25 EINVALID_HTTP_REQUEST = "InvalidHTTPRequest"
26 EINVALID_URI = "InvalidURI"
27 EMALFORMED_JSON = "MalformedJSON"
28 EINVALID_VERSION = "InvalidVersion"
29 EOPT_IN_REQUIRED = "OptInRequired"
30 EPRECONDITION_FAILED = "PreconditionFailed"
31 EREQUEST_EXPIRED = "RequestExpired"
32 ESIGNATURE_DOES_NOT_MATCH = "SignatureDoesNotMatch"
33 )
34 35 // BceError abstracts the error for BCE
36 type BceError interface {
37 error
38 }
39 40 // BceClientError defines the error struct for the client when making request
41 type BceClientError struct{ Message string }
42 43 func (b *BceClientError) Error() string { return b.Message }
44 45 func NewBceClientError(msg string) *BceClientError { return &BceClientError{msg} }
46 47 // BceServiceError defines the error struct for the BCE service when receiving response
48 type BceServiceError struct {
49 Code string
50 Message string
51 RequestId string
52 StatusCode int
53 }
54 55 func (b *BceServiceError) Error() string {
56 ret := "[Code: " + b.Code
57 ret += "; Message: " + b.Message
58 ret += "; RequestId: " + b.RequestId + "]"
59 return ret
60 }
61 62 func NewBceServiceError(code, msg, reqId string, status int) *BceServiceError {
63 return &BceServiceError{code, msg, reqId, status}
64 }
65