-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12291 from thesujai/distributed-error-reporting-t…
…ask5 Distributed Error Reporting: Frontend Error reporting
- Loading branch information
Showing
5 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
kolibri/core/assets/src/api-resources/__tests__/errorReport.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import urls from 'kolibri.urls'; | ||
import Resource from '../errorReport'; | ||
import { | ||
VueErrorReport, | ||
JavascriptErrorReport, | ||
UnhandledRejectionErrorReport, | ||
} from '../../utils/errorReportUtils'; | ||
|
||
/* eslint-env jest */ | ||
jest.mock('kolibri.urls', () => ({ | ||
'kolibri:core:report': jest.fn(), | ||
})); | ||
|
||
describe('Error Report', () => { | ||
beforeEach(() => { | ||
urls['kolibri:core:report'].mockReturnValue('/api/core/report'); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should call api/core/report with VueErrorReport data', () => { | ||
const vueError = new Error('Vue error'); | ||
vueError.stack = 'My stack trace'; | ||
const errorReport = new VueErrorReport(vueError); | ||
|
||
const expectedData = { | ||
error_message: 'Vue error', | ||
traceback: 'My stack trace', | ||
}; | ||
|
||
Resource.client = jest.fn(); | ||
|
||
Resource.report(errorReport); | ||
|
||
expect(Resource.client).toHaveBeenCalledWith({ | ||
url: '/api/core/report', | ||
method: 'post', | ||
data: expectedData, | ||
}); | ||
}); | ||
|
||
it('should call api/core/report with JavascriptErrorReport data', () => { | ||
const jsErrorEvent = { | ||
error: new Error('Javascript error'), | ||
}; | ||
jsErrorEvent.error.stack = 'My stack trace'; | ||
|
||
const errorReport = new JavascriptErrorReport(jsErrorEvent); | ||
|
||
const expectedData = { | ||
error_message: 'Javascript error', | ||
traceback: 'My stack trace', | ||
}; | ||
|
||
Resource.client = jest.fn(); | ||
|
||
Resource.report(errorReport); | ||
|
||
expect(Resource.client).toHaveBeenCalledWith({ | ||
url: '/api/core/report', | ||
method: 'post', | ||
data: expectedData, | ||
}); | ||
}); | ||
|
||
it('should call api/core/report with UnhandledRejectionErrorReport data', () => { | ||
const rejectionEvent = { | ||
reason: new Error('Unhandled rejection'), | ||
}; | ||
rejectionEvent.reason.stack = 'My stack trace'; | ||
|
||
const errorReport = new UnhandledRejectionErrorReport(rejectionEvent); | ||
|
||
const expectedData = { | ||
error_message: 'Unhandled rejection', | ||
traceback: 'My stack trace', | ||
}; | ||
|
||
Resource.client = jest.fn(); | ||
|
||
Resource.report(errorReport); | ||
|
||
expect(Resource.client).toHaveBeenCalledWith({ | ||
url: '/api/core/report', | ||
method: 'post', | ||
data: expectedData, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Resource } from 'kolibri.lib.apiResource'; | ||
import urls from 'kolibri.urls'; | ||
|
||
export default new Resource({ | ||
name: 'errorreports', | ||
report(error) { | ||
const url = urls['kolibri:core:report'](); | ||
const data = error.getErrorReport(); | ||
return this.client({ | ||
url, | ||
method: 'post', | ||
data: data, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class ErrorReport { | ||
constructor(e) { | ||
this.e = e; | ||
} | ||
|
||
getErrorReport() { | ||
throw new Error('getErrorReport() method must be implemented.'); | ||
} | ||
} | ||
|
||
export class VueErrorReport extends ErrorReport { | ||
getErrorReport() { | ||
return { | ||
error_message: this.e.message, | ||
traceback: this.e.stack, | ||
}; | ||
} | ||
} | ||
|
||
export class JavascriptErrorReport extends ErrorReport { | ||
getErrorReport() { | ||
return { | ||
error_message: this.e.error.message, | ||
traceback: this.e.error.stack, | ||
}; | ||
} | ||
} | ||
|
||
export class UnhandledRejectionErrorReport extends ErrorReport { | ||
getErrorReport() { | ||
return { | ||
error_message: this.e.reason.message, | ||
traceback: this.e.reason.stack, | ||
}; | ||
} | ||
} |