Skip to content

Commit 2ac3226

Browse files
committed
add angularJS instructions to the README
1 parent 91a5631 commit 2ac3226

1 file changed

Lines changed: 41 additions & 2 deletions

File tree

README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ Open the page that you instrumented, open the Devtools console and enter the fol
5353

5454
Open Stackdriver Error Reporting at https://console.cloud.google.com/errors to view the error and opt-in to notifications on new errors.
5555

56-
## Setup
56+
57+
## Setup for JavaScript
5758

5859
### Initialization
5960

6061
Here are all the initialization options available:
6162

6263
```HTML
63-
<!-- Warning: This is an experimental library, do not use it on production environments -->
64+
<!-- Warning: This is an experimental library -->
6465
<script src="https://cdn.rawgit.com/GoogleCloudPlatform/stackdriver-errors-js/v0.0.4/dist/stackdriver-errors-concat.min.js"></script>
6566
<script type="text/javascript">
6667
var errorHandler = new StackdriverErrorReporter();
@@ -77,6 +78,8 @@ errorHandler.start({
7778

7879
### Usage
7980

81+
Unhandled exception will now automatically be reported to Stackdriver Error Reporting.
82+
8083
You can change your code to report errors:
8184

8285
When catching an exception:
@@ -104,6 +107,42 @@ Your minified file need to be appended with a comment directive to your source m
104107
//# sourceMappingURL=http://example.com/path/to/your/sourcemap.map
105108
```
106109

110+
111+
## Setup for AngularJS
112+
113+
### Initialization
114+
115+
1. Load the `dist/stackdriver-errors-concat.min.js` JavaScript module.
116+
117+
2. Implement a new [exception handler](https://docs.angularjs.org/api/ng/service/$exceptionHandler) for your AngularJS application:
118+
119+
```JS
120+
angular.module('yourApp', [])
121+
122+
.factory('$exceptionHandler', ['$log', '$window', function($log, $window) {
123+
var StackdriverErrors = new $window.StackdriverErrorReporter();
124+
StackdriverErrors.start({
125+
key: '<my-api-key>',
126+
projectId: '<my-project-id>',
127+
service: '<my-service>', // (optional)
128+
version: '<my-service-version>' // (optional)
129+
});
130+
131+
return function(exception, cause) {
132+
StackdriverErrors.report(exception);
133+
$log.warn('Reported error:', exception, cause);
134+
};
135+
}])
136+
```
137+
138+
### Usage
139+
140+
Uncaught exception in angular expressions will be reported to Stackdriver Error Reporting using this service.
141+
142+
If you wish, you can manually delegate exceptions, e.g. `try { ... } catch(e) { $exceptionHandler(e); }` or simply `$exceptionHandler(e);`.
143+
144+
145+
107146
## FAQ
108147

109148
**Q: Should I use this code in my production application?** A: This is an experimental library. We do not recommend using it on production yet.

0 commit comments

Comments
 (0)