Class: ZuoraConnect::JsonParseErrors

Inherits:
Object
  • Object
show all
Defined in:
lib/middleware/json_parse_errors.rb

Defined Under Namespace

Classes: DynamicRailsError

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ JsonParseErrors

Returns a new instance of JsonParseErrors.



3
4
5
# File 'lib/middleware/json_parse_errors.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/middleware/json_parse_errors.rb', line 7

def call(env)
  begin
    @app.call(env)
  rescue DynamicRailsError => error
    if env['HTTP_ACCEPT'] =~ /application\/json/ || env['CONTENT_TYPE'] =~ /application\/json/
      return [
        400, { "Content-Type" => "application/json" },
        [{"success": false, "reasons": [{"code": 50000090, "message": "Malformed json was submitted." }]}.to_json ]
      ]
    else
      raise error
    end
  end
end