class Ashikawa::Core::ErrorResponse
A response from the server
Constants
- AuthenticationFailed
Status
code for an [Unauthorized Request](httpstatus.es/401)- BadSyntaxStatus
Status
code for a [Bad Request](httpstatus.es/400)- ClientErrorStatuses
All other status codes for client errors
- ResourceNotFoundError
Status
code for a [Not Found Resource](httpstatus.es/404)- ServerErrorStatuses
All status codes for server errors
Public Instance Methods
On completion of the request raise errors depending on the status
@raise [BadSyntax] If the status code is a 400 @raise [AuthenticationFailed] If the status code is a 401 @raise [DocumentNotFoundException] If the status code is 404 and a document was requested @raise [CollectionNotFoundException] If the status code is 404 and a collection was requested @raise [IndexNotFoundException] If the status code is 404 and an index was requested @raise [ResourceNotFoundError] If the status code is 404 and any other resource was requested @raise [ClientError] If the status code is any other 4XX code @raise [ServerError] If the status code is any of the 5XX codes @return nil
# File lib/ashikawa-core/error_response.rb, line 44 def on_complete(env) @body = env[:body] || {} @url = env[:url] case env[:status] when BadSyntaxStatus then bad_syntax when AuthenticationFailed then authentication_failed when ResourceNotFoundError then resource_not_found when ClientErrorStatuses then client_error when ServerErrorStatuses then server_error end end
Private Instance Methods
Raise an Authentication Failed Error
@raise [AuthenticationFailed] @return nil @api private
# File lib/ashikawa-core/error_response.rb, line 73 def authentication_failed raise Core::AuthenticationFailed end
Raise a Bad Syntax Error
@raise [BadSyntax] @return nil @api private
# File lib/ashikawa-core/error_response.rb, line 64 def bad_syntax raise BadSyntax, error end
Raise a Client Error for a given body
@raise [ClientError] @return nil @api private
# File lib/ashikawa-core/error_response.rb, line 82 def client_error raise ClientError, error end
Read the error message for the request
@param [String] The raw body of the request @return [String] The formatted error message @api private
# File lib/ashikawa-core/error_response.rb, line 133 def error @body.empty? ? nil : "#{@body['errorNum']}: #{@body['errorMessage']}" end
Raise the fitting ResourceNotFoundException
@raise [DocumentNotFoundException, CollectionNotFoundException
, IndexNotFoundException] @return nil @api private
# File lib/ashikawa-core/error_response.rb, line 100 def resource_not_found raise case @url.path when %r{\A(/_db/[^/]+)?/_api/document} then DocumentNotFoundException when %r{\A(/_db/[^/]+)?/_api/collection} then CollectionNotFoundException when %r{\A(/_db/[^/]+)?/_api/index} then IndexNotFoundException when %r{\A(/_db/[^/]+)?/_api/gharial} then resource_not_found_in_graph_scope else ResourceNotFound end, error end
Raise fitting ResourceNotFoundException within the Graph
module
@raise [DocumentNotFoundException, CollectionNotFoundException
, GraphNotFoundException
, ResourceNotFound] @return nil @api private
# File lib/ashikawa-core/error_response.rb, line 115 def resource_not_found_in_graph_scope raise case @body['errorMessage'] when 'graph not found' then GraphNotFoundException when 'collection not found' then CollectionNotFoundException when 'document not found' then DocumentNotFoundException when 'collection used in orphans' then VertexCollectionAlreadyPresent when 'collection used in edge def' then VertexCollectionAlreadyPresent when 'multi use of edge collection in edge def' then EdgeCollectionAlreadyPresent when 'edge collection already used in edge def' then EdgeCollectionAlreadyPresent else ResourceNotFound end, error end
Raise a Server Error for a given body
@raise [ServerError] @return nil @api private
# File lib/ashikawa-core/error_response.rb, line 91 def server_error raise ServerError, error end