Exception: VCAP::Services::Base::Error::ServiceError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/base/service_error.rb

Constant Summary collapse

HTTP_BAD_REQUEST =

HTTP status code

400
HTTP_NOT_AUTHORIZED =
401
HTTP_FORBIDDEN =
403
HTTP_NOT_FOUND =
404
HTTP_INTERNAL =
500
HTTP_NOT_IMPLEMENTED =
501
HTTP_SERVICE_UNAVAIL =
503
HTTP_GATEWAY_TIMEOUT =
504
INVALID_CONTENT =

30000 - 30099 400 Bad Request

[30000, HTTP_BAD_REQUEST, 'Invalid Content-Type']
MALFORMATTED_REQ =
[30001, HTTP_BAD_REQUEST, 'Malformatted request']
UNKNOWN_PLAN_UNIQUE_ID =
[30002, HTTP_BAD_REQUEST, 'Unknown unique_id']
UNKNOWN_PLAN =
[30003, HTTP_BAD_REQUEST, 'Unknown plan %s']
UNSUPPORTED_VERSION =
[30004, HTTP_BAD_REQUEST, 'Unsupported version %s']
NOT_AUTHORIZED =

30100 - 30199 401 Unauthorized

[30100, HTTP_NOT_AUTHORIZED, 'Not authorized']
NOT_FOUND =

30300 - 30399 404 Not Found

[30300, HTTP_NOT_FOUND, '%s not found']
INTERNAL_ERROR =

30500 - 30599 500 Internal Error

[30500, HTTP_INTERNAL, 'Internal Error']
EXTENSION_NOT_IMPL =
[30501, HTTP_NOT_IMPLEMENTED, "Service extension %s is not implemented."]
NODE_OPERATION_TIMEOUT =
[30502, HTTP_INTERNAL, "Node operation timeout"]
SERVICE_START_TIMEOUT =
[30503, HTTP_INTERNAL, "Service start timeout"]
WARDEN_RUN_COMMAND_FAILURE =
[30504, HTTP_INTERNAL, "Failed to run command %s in warden container %s, exit status: %d, stdout: %s, stderr: %s"]
SERVICE_UNAVAILABLE =

30600 - 30699 503 Service Unavailable

[30600, HTTP_SERVICE_UNAVAIL, 'Service unavailable']
GATEWAY_TIMEOUT =

30700 - 30799 500 Gateway Timeout

[30700, HTTP_GATEWAY_TIMEOUT, 'Gateway timeout']
OVER_QUOTA =

30800 - 30899 500 Lifecycle error

[30800, HTTP_INTERNAL, "Instance %s has %s snapshots. Quota is %s "]
JOB_QUEUE_TIMEOUT =
[30801, HTTP_INTERNAL, "Job timeout after waiting for %s seconds."]
JOB_TIMEOUT =
[30802, HTTP_INTERNAL, "Job is killed since it runs longer than ttl: %s seconds."]
BAD_SERIALIZED_DATAFILE =
[30803, HTTP_INTERNAL, "Invalid serialized data file from: %s"]
FILESIZE_TOO_LARGE =
[30804, HTTP_BAD_REQUEST, "Size of file from url %s is %s, max allowed %s"]
TOO_MANY_REDIRECTS =
[30805, HTTP_BAD_REQUEST, "Too many redirects from url:%s, max redirects allowed is %s"]
FILE_CORRUPTED =
[30806, HTTP_BAD_REQUEST, "Serialized file is corrupted."]
REDIS_CONCURRENT_UPDATE =
[30807, HTTP_INTERNAL, "Server busy, please try again later."]
INVALID_SNAPSHOT_NAME =
[30808, HTTP_BAD_REQUEST, "Invalid snapshot name. %s"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, *args) ⇒ ServiceError

31000 - 32000 Service-specific Error Defined in services directory, for example mongodb/lib/mongodb_service/



71
72
73
74
75
# File 'lib/base/service_error.rb', line 71

def initialize(code, *args)
  @http_status = code[1]
  @error_code  = code[0]
  @error_msg   = sprintf(code[2], *args)
end

Instance Attribute Details

#error_codeObject (readonly)

Returns the value of attribute error_code.



10
11
12
# File 'lib/base/service_error.rb', line 10

def error_code
  @error_code
end

#error_msgObject (readonly)

Returns the value of attribute error_msg.



10
11
12
# File 'lib/base/service_error.rb', line 10

def error_msg
  @error_msg
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



10
11
12
# File 'lib/base/service_error.rb', line 10

def http_status
  @http_status
end

Instance Method Details

#to_hashObject



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/base/service_error.rb', line 81

def to_hash
  {
    'status' => @http_status,
    'msg' => {
      'code' => @error_code,
      'description' => @error_msg,
      'error' => {
        'backtrace' => backtrace,
        'types' => self.class.ancestors.map(&:name) - Object.ancestors.map(&:name)
      }
    }
  }
end

#to_sObject



77
78
79
# File 'lib/base/service_error.rb', line 77

def to_s
  "Error Code: #{@error_code}, Error Message: #{@error_msg}"
end