Class: ForestAdminAgent::Http::ErrorTranslator

Inherits:
Object
  • Object
show all
Defined in:
lib/forest_admin_agent/http/error_translator.rb

Class Method Summary collapse

Class Method Details

.translate(error) ⇒ HttpException

Translate any exception to its appropriate HTTP error representation

Parameters:

  • error (Exception)

    The error to translate

Returns:

  • (HttpException)

    The translated error with HTTP-specific properties



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/forest_admin_agent/http/error_translator.rb', line 10

def self.translate(error)
  return error if error.is_a?(Exceptions::HttpException)

  name = error.class.name.split('::').last

  status = get_error_status(error)

  message = get_error_message(error)

  data = get_error_data(error)

  custom_headers = get_custom_headers(error)

  Exceptions::HttpException.new(
    status,
    name,
    message,
    data,
    custom_headers
  )
end