Exception: Hook0::ClientError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/hook0/errors.rb

Overview

The one failure this client reports.

Sending an event, upserting an event type and verifying a webhook all raise this, so a caller has one thing to rescue whatever it asked the client to do. The failures the API reports are a different matter: those are the problems it names in its own error contract, and the generated half of this gem raises one exception per problem.

The constructors below are what the client raises through; each one exists so that the same situation always reads the same way, whichever call it came out of.

Class Method Summary collapse

Class Method Details

.available_event_types(detail) ⇒ ClientError

The list of event types the application already declares could not be read.

Parameters:

  • detail (String)

Returns:



65
66
67
# File 'lib/hook0/errors.rb', line 65

def self.available_event_types(detail)
  new("Getting available event types failed: #{detail}")
end

.creating_event_type(event_type, detail) ⇒ ClientError

An event type that could not be created.

Parameters:

  • event_type (String)
  • detail (String)

Returns:



74
75
76
# File 'lib/hook0/errors.rb', line 74

def self.creating_event_type(event_type, detail)
  new("Creating event type '#{event_type}' failed: #{detail}")
end

.event_sending(event_id, detail) ⇒ ClientError

A send the API refused for a reason repeating it would not change.

Parameters:

  • event_id (String)
  • detail (String)

Returns:



19
20
21
# File 'lib/hook0/errors.rb', line 19

def self.event_sending(event_id, detail)
  new("Sending event #{event_id} failed: #{detail}")
end

.invalid_event_type(event_type) ⇒ ClientError

An event type that does not read as service.resource_type.verb.

Parameters:

  • event_type (String)

Returns:



57
58
59
# File 'lib/hook0/errors.rb', line 57

def self.invalid_event_type(event_type)
  new("Provided event type '#{event_type}' does not have a valid syntax (service.resource_type.verb)")
end

.payload_too_large(event_id, size, maximum) ⇒ ClientError

A payload above what the client agrees to send, refused before a socket is opened.

Parameters:

  • event_id (String)
  • size (Integer)
  • maximum (Integer)

Returns:



46
47
48
49
50
51
# File 'lib/hook0/errors.rb', line 46

def self.payload_too_large(event_id, size, maximum)
  new(
    "Sending event #{event_id} failed: event payload is #{size} bytes, which is more than " \
    "the #{maximum} bytes this client sends at most; nothing was sent"
  )
end

.retries_exhausted(event_id, attempts, waited, detail) ⇒ ClientError

A send that ran out of attempts, or out of the delay budget its attempts share.

A send that gave up and a single refused request are otherwise indistinguishable to a caller, which is the difference between a transient outage and a request that will never be accepted.

Parameters:

  • event_id (String)
  • attempts (Integer)
  • waited (Float)

    seconds spent waiting between the attempts

  • detail (String)

Returns:



33
34
35
36
37
38
# File 'lib/hook0/errors.rb', line 33

def self.retries_exhausted(event_id, attempts, waited, detail)
  new(
    "Sending event #{event_id} failed: gave up after #{attempts} attempts " \
    "spread over #{format("%.3f", waited)}s of retry delay; last failure: #{detail}"
  )
end