Commit 666ce5515732554769af38a50f32f02cb94b2891

Authored by Stephen Crosby
1 parent a0929bc8
Exists in master

#1044 support and document the airbrake-js xhr reporter

README.md
... ... @@ -243,17 +243,20 @@ This tab will be hidden if no user information is available.
243 243  
244 244 Javascript error notifications
245 245 --------------------------------------
246   -
247 246 You can log javascript errors that occur in your application by including the
248 247 [airbrake-js](https://github.com/airbrake/airbrake-js) javascript library.
249 248  
250   -Install airbrake-js according to the docs at
251   -[airbrake-js](https://github.com/airbrake/airbrake-js) and set your project and
252   -host as early as possible:
  249 +Install airbrake-js according to the docs at and set your project and host as
  250 +soon as you want to start reporting errors. Then follow along with the
  251 +documentation at https://github.com/airbrake/airbrake-js/blob/master/README.md
253 252  
254 253 ```javascript
255   -Airbrake.setProject("ERRBIT API KEY", "ERRBIT API KEY");
256   -Airbrake.setHost("http://errbit.yourdomain.com");
  254 +var airbrake = new airbrakeJs.Client({
  255 + projectId: 'ERRBIT API KEY',
  256 + projectKey: 'ERRBIT API KEY (again)',
  257 + reporter: 'xhr',
  258 + host: 'https://myerrbit.com'
  259 +});
257 260 ```
258 261  
259 262 Plugins and Integrations
... ...
app/controllers/api/v3/notices_controller.rb
... ... @@ -10,6 +10,7 @@ class Api::V3::NoticesController < ApplicationController
10 10 def create
11 11 response.headers['Access-Control-Allow-Origin'] = '*'
12 12 response.headers['Access-Control-Allow-Headers'] = 'origin, content-type, accept'
  13 + return render(status: 200, text: '') if request.method == 'OPTIONS'
13 14  
14 15 report = AirbrakeApi::V3::NoticeParser.new(
15 16 params.merge(JSON.parse(request.raw_post) || {})).report
... ...
config/routes.rb
... ... @@ -64,7 +64,7 @@ Rails.application.routes.draw do
64 64 end
65 65  
66 66 match '/api/v3/projects/:project_id/create-notice' => 'api/v3/notices#create', via: [:post]
67   - match '/api/v3/projects/:project_id/notices' => 'api/v3/notices#create', via: [:post]
  67 + match '/api/v3/projects/:project_id/notices' => 'api/v3/notices#create', via: [:post, :options]
68 68  
69 69 root to: 'apps#index'
70 70 end
... ...
spec/controllers/api/v3/notices_controller_spec.rb
... ... @@ -12,6 +12,12 @@ describe Api::V3::NoticesController, type: :controller do
12 12 expect(response.headers['Access-Control-Allow-Headers']).to eq('origin, content-type, accept')
13 13 end
14 14  
  15 + it 'responds to an OPTIONS request' do
  16 + process :create, 'OPTIONS', project_id: 'nothingspecial'
  17 + expect(response.headers['Access-Control-Allow-Origin']).to eq('*')
  18 + expect(response.headers['Access-Control-Allow-Headers']).to eq('origin, content-type, accept')
  19 + end
  20 +
15 21 it 'returns created notice id in json format' do
16 22 post :create, legit_body, legit_params
17 23 notice = Notice.last
... ...