Class: Api::V3::NoticesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/api/v3/notices_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/api/v3/notices_controller.rb', line 7

def create
  response.headers['Access-Control-Allow-Origin'] = '*'
  response.headers['Access-Control-Allow-Headers'] = 'origin, content-type, accept'

  if !request.options?
    report = AirbrakeApi::V3::NoticeParser.new(params).report

    if report.valid?
      if report.should_keep?
        report.generate_notice!
        render json: {
          notice: {
            id: report.notice.id
          }
        }
      else
        render text: 'Notice for old app version ignored'
      end
    else
      render text: 'Your API key is unknown', status: 422
    end
  else
    render nothing: true
  end
rescue AirbrakeApi::ParamsError
  render text: 'Invalid request', status: 400
end