Exception: PostHog::EmailError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/posthog/email_error.rb

Overview

PostHog did not queue the email, or the client could not tell whether it did.

Branch on #code, PostHog's stable error code, or on #name, a coarse category of the failure. The message never contains the secret key or the request body.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, message:, status_code: nil, why: nil, fix: nil, docs_url: nil, field: nil, retry_after: nil) ⇒ EmailError

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of EmailError.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/posthog/email_error.rb', line 28

def initialize(code:, message:, status_code: nil, why: nil, fix: nil, docs_url: nil, field: nil, retry_after: nil)
  super(message)
  @name = self.class.name_for(status_code, code)
  @code = code
  @status_code = status_code
  @why = why
  @fix = fix
  @docs_url = docs_url
  @field = field
  @retry_after = retry_after
end

Instance Attribute Details

#code ⇒ String (readonly)

Returns PostHog's error code, such as quota_limited, or an SDK code such as network_error.

Returns:

  • (String) —

    PostHog's error code, such as quota_limited, or an SDK code such as network_error.



13
14
15
# File 'lib/posthog/email_error.rb', line 13

def code
  @code
end

#docs_url ⇒ String? (readonly)

Returns A link to the docs for this error.

Returns:

  • (String, nil) —

    A link to the docs for this error.



21
22
23
# File 'lib/posthog/email_error.rb', line 21

def docs_url
  @docs_url
end

#field ⇒ String? (readonly)

Returns The request field the error is about, when PostHog named one.

Returns:

  • (String, nil) —

    The request field the error is about, when PostHog named one.



23
24
25
# File 'lib/posthog/email_error.rb', line 23

def field
  @field
end

#fix ⇒ String? (readonly)

Returns How to fix the request.

Returns:

  • (String, nil) —

    How to fix the request.



19
20
21
# File 'lib/posthog/email_error.rb', line 19

def fix
  @fix
end

#name ⇒ String (readonly)

Returns A coarse category of the failure, such as validation_error, rate_limit_exceeded or service_unavailable.

Returns:

  • (String) —

    A coarse category of the failure, such as validation_error, rate_limit_exceeded or service_unavailable.



11
12
13
# File 'lib/posthog/email_error.rb', line 11

def name
  @name
end

#retry_after ⇒ Float? (readonly)

Returns How long PostHog asked the client to wait before it sends again, in seconds.

Returns:

  • (Float, nil) —

    How long PostHog asked the client to wait before it sends again, in seconds.



25
26
27
# File 'lib/posthog/email_error.rb', line 25

def retry_after
  @retry_after
end

#status_code ⇒ Integer? (readonly)

Returns The HTTP status, when PostHog answered, or file storage's for attachment_upload_failed.

Returns:

  • (Integer, nil) —

    The HTTP status, when PostHog answered, or file storage's for attachment_upload_failed.



15
16
17
# File 'lib/posthog/email_error.rb', line 15

def status_code
  @status_code
end

#why ⇒ String? (readonly)

Returns Why PostHog refused the email.

Returns:

  • (String, nil) —

    Why PostHog refused the email.



17
18
19
# File 'lib/posthog/email_error.rb', line 17

def why
  @why
end

Class Method Details

.name_for(status_code, code) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/posthog/email_error.rb', line 49

def self.name_for(status_code, code)
  return status_code.to_i >= 500 ? 'service_unavailable' : 'application_error' if code == 'attachment_upload_failed'
  return 'missing_api_key' if code == 'missing_secret_key' || status_code == 401
  return SDK_ERROR_NAMES.fetch(code, 'application_error') if status_code.nil?

  case status_code
  when 400 then 'validation_error'
  when 403 then 'invalid_permission'
  when 404 then 'not_found'
  when 409 then code == 'template_outdated' ? 'validation_error' : 'concurrent_idempotent_requests'
  when 422 then code == 'idempotency_key_reused' ? 'invalid_idempotent_request' : 'validation_error'
  when 429 then code == 'quota_limited' ? 'monthly_quota_exceeded' : 'rate_limit_exceeded'
  when 503 then 'service_unavailable'
  else 'application_error'
  end
end