Class: Minds::MiddlewareErrors
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Minds::MiddlewareErrors
- Defined in:
- lib/minds.rb
Instance Method Summary collapse
-
#call(env) ⇒ Object
Handles API error responses and provides detailed logging.
Instance Method Details
#call(env) ⇒ Object
Handles API error responses and provides detailed logging
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/minds.rb', line 20 def call(env) @app.call(env) rescue Faraday::Error => e raise e unless e.response.is_a?(Hash) logger = Logger.new($stdout) logger.formatter = proc do |_severity, datetime, _progname, msg| = datetime.strftime("%Y-%m-%d %H:%M:%S.%L") error_prefix = "\033[31m[Minds #{VERSION}] #{} ERROR" error_suffix = "\033[0m" = msg.split("\n").map do |line| "#{' ' * 15}#{line}" end.join("\n") "#{error_prefix} Rest Client Error\n#{}#{error_suffix}\n" end logger.error(e.response[:body]) raise e end |