Class: Bistrochat::ErrorMessages

Inherits:
Object
  • Object
show all
Defined in:
app/services/bistrochat/error_messages.rb

Constant Summary collapse

DEFAULT_ERROR =
'Sorry, something went wrong'
SUPPLIER_ERROR =
'Supplier Error:'
UNAVAILABILITY_ERROR =

List of error messages from Bistrochat API

'No tables are available for current selection.'
TIME_HAS_PASSED =
'Selected time occurs in the past.'
CANNOT_UPDATE_CANCELED_RESERVATION_ERROR =
'Sorry, you cannot modify the status of a CANCELED reservation in Bistrochat'
CANNOT_UPDATE_STATUS_ON_HUNGRYHUB_ERROR =
'Sorry, the status of this reservation can only be changed from the Bistrochat dashboard'
BLOCKAGE_EXPIRED_UPDATE_ERROR =
'Block could not be updated'
ERROR_MESSAGE_MAP =

map of error messages from Bistrochat API to HungryHub error messages

{
  UNAVAILABILITY_ERROR => I18n.t('inventory.not_available'),
  TIME_HAS_PASSED => I18n.t('inventory.time_has_passed'),
}.freeze
KNOWN_ERRORS =

list of error messages from Bistrochat API that should not be logged

ERROR_MESSAGE_MAP.keys.freeze
INVENTORY_ERRORS =

list of inventory errors

[UNAVAILABILITY_ERROR, TIME_HAS_PASSED].freeze

Class Method Summary collapse

Class Method Details

.error_message(actor, error) ⇒ String

Returns the error message based on the actor and error code.

Parameters:

  • actor (Symbol)

    The actor for which the error message is generated.

  • error (String)

    The error code.

Returns:

  • (String)

    The error message.



35
36
37
38
39
40
41
42
43
44
45
# File 'app/services/bistrochat/error_messages.rb', line 35

def self.error_message(actor, error)
  return DEFAULT_ERROR if actor.blank? || error.blank?

  if actor.to_sym == :user
    ERROR_MESSAGE_MAP[error] || DEFAULT_ERROR
  else
    return "#{SUPPLIER_ERROR} #{ERROR_MESSAGE_MAP[error]}" if ERROR_MESSAGE_MAP[error].present?

    "#{SUPPLIER_ERROR} #{error}"
  end
end