lib/goliath/api.rb
# {#call} is executed automatically by the middleware chain and will setup
# the environment for the {#response} method to execute. This includes setting
# up a new Fiber, handing any exceptions thrown from the API and executing
# the appropriate callback method for the API.
#
# @param env [Goliath::Env] The request environment
# @return [Goliath::Connection::AsyncResponse] An async response.
{#call} is executed automatically by the middleware chain and will setup
the environment for the {#response} method to execute. This includes setting
up a new Fiber, handing any exceptions thrown from the API and executing
the appropriate callback method for the API.
{ #call } is executed automatically by the middleware chain and will setup the environment for the { #response } method to execute . This includes setting up a new Fiber handing any exceptions thrown from the API and executing the appropriate callback method for the API .
def call(env)
      begin
        Thread.current[GOLIATH_ENV] = env
        status, headers, body = response(env)
        if status
          if body == Goliath::Response::STREAMING
            env[STREAM_START].call(status, headers)
          else
            env[ASYNC_CALLBACK].call([status, headers, body])
          end
        end
      rescue Goliath::Validation::Error => e
        env[RACK_EXCEPTION] = e
        env[ASYNC_CALLBACK].call(validation_error(e.status_code, e.message))
      rescue Exception => e
        env.logger.error(e.message)
        env.logger.error(e.backtrace.join("\n"))
        env[RACK_EXCEPTION] = e
        env[ASYNC_CALLBACK].call(validation_error(500, e.message))
      end
      Goliath::Connection::AsyncResponse
    end
def call ( env ) begin Thread . current [ GOLIATH_ENV ] = env status , headers , body = response ( env ) if status if body == Goliath :: Response :: STREAMING env [ STREAM_START ] . call ( status , headers ) else env [ ASYNC_CALLBACK ] . call ( [ status , headers , body ] ) end end rescue Goliath :: Validation :: Error => e env [ RACK_EXCEPTION ] = e env [ ASYNC_CALLBACK ] . call ( validation_error ( e . status_code , e . message ) ) rescue Exception => e env . logger . error ( e . message ) env . logger . error ( e . backtrace . join ( "\n" ) ) env [ RACK_EXCEPTION ] = e env [ ASYNC_CALLBACK ] . call ( validation_error ( 500 , e . message ) ) end Goliath :: Connection :: AsyncResponse end
{#call} is executed automatically by the middleware chain and will setup
the environment for the {#response} method to execute.
{ #call } is executed automatically by the middleware chain and will setup the environment for the { #response } method to execute .
An async response.
An async response .
Goliath::Connection::AsyncResponse
env
The request environment
The request environment