Exception: ServiceStack::WebServiceException
- Inherits:
-
StandardError
- Object
- StandardError
- ServiceStack::WebServiceException
- Defined in:
- lib/servicestack/web_service_exception.rb
Overview
Raised for failed API Requests, containing the HTTP Status Code and the structured ResponseStatus error when the Server returned one.
begin
client.send(CreateBooking.new)
rescue ServiceStack::WebServiceException => e
puts e.status_code # 400
puts e.error_code # "NotEmpty"
puts e.field_error('Name') # "'Name' must not be empty."
end
Instance Attribute Summary collapse
-
#inner_exception ⇒ Object
readonly
Returns the value of attribute inner_exception.
-
#response_body ⇒ Object
readonly
Returns the value of attribute response_body.
-
#response_status ⇒ Object
readonly
Returns the value of attribute response_status.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#status_description ⇒ Object
readonly
Returns the value of attribute status_description.
Instance Method Summary collapse
-
#error_code ⇒ Object
The ErrorCode of the error, e.g.
-
#error_message ⇒ Object
The error message.
-
#field_error(field_name) ⇒ Object
The validation error message for the field, if it has one.
-
#field_errors ⇒ Object
Any field validation errors.
- #forbidden? ⇒ Boolean
-
#initialize(message = nil, status_code: 0, status_description: nil, response_status: nil, response_body: nil, inner_exception: nil) ⇒ WebServiceException
constructor
A new instance of WebServiceException.
- #not_found? ⇒ Boolean
- #unauthorized? ⇒ Boolean
- #validation_error? ⇒ Boolean
Constructor Details
#initialize(message = nil, status_code: 0, status_description: nil, response_status: nil, response_body: nil, inner_exception: nil) ⇒ WebServiceException
Returns a new instance of WebServiceException.
17 18 19 20 21 22 23 24 25 |
# File 'lib/servicestack/web_service_exception.rb', line 17 def initialize( = nil, status_code: 0, status_description: nil, response_status: nil, response_body: nil, inner_exception: nil) super( || status_description || "HTTP Error #{status_code}") @status_code = status_code @status_description = status_description @response_status = response_status @response_body = response_body @inner_exception = inner_exception end |
Instance Attribute Details
#inner_exception ⇒ Object (readonly)
Returns the value of attribute inner_exception.
15 16 17 |
# File 'lib/servicestack/web_service_exception.rb', line 15 def inner_exception @inner_exception end |
#response_body ⇒ Object (readonly)
Returns the value of attribute response_body.
15 16 17 |
# File 'lib/servicestack/web_service_exception.rb', line 15 def response_body @response_body end |
#response_status ⇒ Object (readonly)
Returns the value of attribute response_status.
15 16 17 |
# File 'lib/servicestack/web_service_exception.rb', line 15 def response_status @response_status end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
15 16 17 |
# File 'lib/servicestack/web_service_exception.rb', line 15 def status_code @status_code end |
#status_description ⇒ Object (readonly)
Returns the value of attribute status_description.
15 16 17 |
# File 'lib/servicestack/web_service_exception.rb', line 15 def status_description @status_description end |
Instance Method Details
#error_code ⇒ Object
The ErrorCode of the error, e.g. "NotFound".
28 |
# File 'lib/servicestack/web_service_exception.rb', line 28 def error_code = @response_status&.error_code |
#error_message ⇒ Object
The error message.
31 |
# File 'lib/servicestack/web_service_exception.rb', line 31 def = @response_status&. || |
#field_error(field_name) ⇒ Object
The validation error message for the field, if it has one.
37 |
# File 'lib/servicestack/web_service_exception.rb', line 37 def field_error(field_name) = @response_status&.field_error(field_name) |
#field_errors ⇒ Object
Any field validation errors.
34 |
# File 'lib/servicestack/web_service_exception.rb', line 34 def field_errors = @response_status&.errors || [] |
#forbidden? ⇒ Boolean
40 |
# File 'lib/servicestack/web_service_exception.rb', line 40 def forbidden? = @status_code == 403 |
#not_found? ⇒ Boolean
41 |
# File 'lib/servicestack/web_service_exception.rb', line 41 def not_found? = @status_code == 404 |
#unauthorized? ⇒ Boolean
39 |
# File 'lib/servicestack/web_service_exception.rb', line 39 def = @status_code == 401 |
#validation_error? ⇒ Boolean
42 |
# File 'lib/servicestack/web_service_exception.rb', line 42 def validation_error? = !field_errors.empty? |