Class: Grumlin::RequestErrorFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/grumlin/request_error_factory.rb

Constant Summary collapse

ERRORS =
{
  499 => Grumlin::InvalidRequestArgumentsError,
  500 => Grumlin::ServerError,
  595 => Grumlin::FailStepError,
  597 => Grumlin::ScriptEvaluationError,
  599 => Grumlin::ServerSerializationError,
  598 => Grumlin::ServerTimeoutError,

  401 => Grumlin::ClientSideError,
  407 => Grumlin::ClientSideError,
  498 => Grumlin::ClientSideError
}.freeze
VERTEX_ALREADY_EXISTS =

Neptune presumably returns message as a JSON string of format

"requestId":"UUID",
"code":"ConcurrentModificationException"

Currently we simply search for substrings to identify the exact error TODO: parse json and use ‘code` instead

"Vertex with id already exists:"
EDGE_ALREADY_EXISTS =
"Edge with id already exists:"
CONCURRENT_VERTEX_INSERT_FAILED =
"Failed to complete Insert operation for a Vertex due to conflicting concurrent"
CONCURRENT_VERTEX_PROPERTY_INSERT_FAILED =
"Failed to complete Insert operation for a VertexProperty due to conflicting concurrent"
CONCURRENT_EDGE_PROPERTY_INSERT_FAILED =
"Failed to complete Insert operation for a EdgeProperty due to conflicting concurrent"
CONCURRENT_EDGE_INSERT_FAILED =
"Failed to complete Insert operation for an Edge due to conflicting concurrent"
CONCURRENCT_MODIFICATION_FAILED =
"Failed to complete operation due to conflicting concurrent"

Class Method Summary collapse

Class Method Details

.already_exists_error(status) ⇒ Object



55
56
57
58
59
# File 'lib/grumlin/request_error_factory.rb', line 55

def already_exists_error(status)
  return Grumlin::VertexAlreadyExistsError if status[:message]&.include?(VERTEX_ALREADY_EXISTS)

  Grumlin::EdgeAlreadyExistsError if status[:message]&.include?(EDGE_ALREADY_EXISTS)
end

.build(request, response) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/grumlin/request_error_factory.rb', line 38

def build(request, response)
  status = response[:status]
  query = request[:request]

  if (error = ERRORS[status[:code]])
    return (
      already_exists_error(status) ||
      concurrent_modification_error(status) ||
      error
    ).new(status, query)
  end

  return unless Grumlin::RequestDispatcher::SUCCESS[status[:code]].nil?

  Grumlin::UnknownResponseStatus.new(status)
end

.concurrent_modification_error(status) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/grumlin/request_error_factory.rb', line 61

def concurrent_modification_error(status) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  return Grumlin::ConcurrentVertexInsertFailedError if status[:message]&.include?(CONCURRENT_VERTEX_INSERT_FAILED)
  if status[:message]&.include?(CONCURRENT_VERTEX_PROPERTY_INSERT_FAILED)
    return Grumlin::ConcurrentVertexPropertyInsertFailedError
  end
  return Grumlin::ConcurrentEdgeInsertFailedError if status[:message]&.include?(CONCURRENT_EDGE_INSERT_FAILED)
  if status[:message]&.include?(CONCURRENT_EDGE_PROPERTY_INSERT_FAILED)
    return Grumlin::ConcurrentEdgePropertyInsertFailedError
  end

  Grumlin::ConcurrentModificationError if status[:message]&.include?(CONCURRENCT_MODIFICATION_FAILED)
end