Sha256: 68391bd596adaf2f27689311ba50a44cf5c4fa4db53d2ff8bb0d884c1bbc3ad6

Contents?: true

Size: 582 Bytes

Versions: 8

Compression:

Stored size: 582 Bytes

Contents

# Intercepts excpetion from the middlewares to handled those as JSON responses
class Robustness

  def initialize(app)
    @app = app
  end

  # Rack API call for rescue from the exceptions
  def call(env)
    @app.call(env)
  rescue Apartment::SchemaNotFound => ex
    [422, { 'Content-Type' => 'application/json' }, [ {errors: {subdomain:["Invalid subdomain"]}}.to_json ] ]  # suppose the message can be safely used
  rescue SecurityError => ex
    [403, { 'Content-Type' => 'application/json' }, [ ex.message ] ]
  ensure
    env['rack.errors'].write(ex.message) if ex
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cadenero-0.0.2.b10 app/extenders/middleware/robustness.rb
cadenero-0.0.2.b8 app/extenders/middleware/robustness.rb
cadenero-0.0.2.b7 app/extenders/middleware/robustness.rb
cadenero-0.0.2.b6 app/extenders/middleware/robustness.rb
cadenero-0.0.2.b5 app/extenders/middleware/robustness.rb
cadenero-0.0.2.b4 app/extenders/middleware/robustness.rb
cadenero-0.0.2.b2 app/extenders/middleware/robustness.rb
cadenero-0.0.2.b1 app/extenders/middleware/robustness.rb