Class: Trailblazer::Endpoint::Adapter::API

Inherits:
Web
  • Object
show all
Defined in:
lib/trailblazer/endpoint/adapter.rb

Overview

Web

Defined Under Namespace

Classes: Errors

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Web

#_401_status, #_403_status, #_404_status, #protocol_failure

Class Method Details

.insert_error_handler_steps(adapter) ⇒ Object

TODO: evaluate if needed?



65
66
67
68
69
# File 'lib/trailblazer/endpoint/adapter.rb', line 65

def self.insert_error_handler_steps(adapter) # TODO: evaluate if needed?
  adapter = Class.new(adapter) do
    API.insert_error_handler_steps!(self)
  end
end

.insert_error_handler_steps!(adapter) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/trailblazer/endpoint/adapter.rb', line 71

def self.insert_error_handler_steps!(adapter)
  adapter.instance_exec do
    step :handle_not_authenticated, magnetic_to: :not_authenticated, Output(:success) => Track(:not_authenticated), before: :_401_status
    step :handle_not_authorized, magnetic_to: :not_authorized, Output(:success) => Track(:not_authorized), before: :_403_status
    # step :handle_not_found, magnetic_to: :not_found, Output(:success) => Track(:not_found), Output(:failure) => Track(:not_found)
    step :handle_invalid_data, before: :_422_status, magnetic_to: :failure, Output(:success) => Track(:failure)
  end
end

Instance Method Details

#_200_status(ctx, success_status: 200) ⇒ Object



54
55
56
# File 'lib/trailblazer/endpoint/adapter.rb', line 54

def _200_status(ctx, success_status: 200, **)
  ctx[:status] = success_status
end

#_422_status(ctx) ⇒ Object



60
61
62
# File 'lib/trailblazer/endpoint/adapter.rb', line 60

def _422_status(ctx, **)
  ctx[:status] = 422
end