Run Code when AngularJS has an Error - angularjs

Question: How can you run code when Angular has an error like Uncaught Error: [$injector:moduler]
Story: Our team would like to be notified when a user has an error with our angular application. We already have a setup if an $http request has an error we have a $httpProvider.interceptors that catches the error and notifies us about the error and who had it, which works great. The problem is we don't have any way of being notified when an angular error happens.
What we have tried: I first thought Angular used console.error so I tried something like this.
console.errorBack = console.error;
console.error = function(){
//notify us about the error
console.errorBack.apply(null,Array.prototype.slice.call(arguments));
};
Which I found does not work as Angular does not use console.error for there error messaging system. So I looked at the source code for Angular but I could not find the code that controls the error system to append to it.

Related

Electron-React error: I keep getting undefined error while reading 'ipcRenderer'

I am trying to create a desktop application using Electron and React.
I set the basic settings using electron-react-boilerplate.
https://github.com/electron-react-boilerplate/electron-react-boilerplate
However, I continued to receive can't resolve fs module not found error.
To solve this error, I performed the method suggested in document https://electron-react-boilerplate.js.org/docs/native-modules/#native-modules-in-electron-react-boilerplate. (activate node integration)
Then I got an error Uncaught TypeError: Cannot read properties of undefined (reading 'ipcRenderer'). but strangely, an error warning window appears, but the app runs normally.
How can I get rid of this error?
currently, i comment all of following code in src/renderer/index.tsx
// calling IPC exposed from preload script
window.electron.ipcRenderer.once('ipc-example', (arg) => {
// eslint-disable-next-line no-console
console.log(arg);
});
window.electron.ipcRenderer.myPing();

Catching and handling errors with Apollo Client

I'm trying to handle errors with Apollo in react gracefully. So the idea is whenever the user encounters an error of some sort (500 or anything else). I want to just show a message like 'something went wrong, please try again later'.
Upon the first render of the component this works fine (the error is present in data.error) but when I leave the route and the component is unmounted, it throws.
At the moment I cannot prevent it from throwing an error. I've tried pretty much everything in this thread: https://github.com/apollographql/react-apollo/issues/604#issuecomment-355648596
link-error: Logs the errors, but doesn't prevent it from throwing
hoc: Logs the errors, but doesn't prevent it from throwing
componentDidCatch: Doesn't do anything
errorPolicy: Prevents errors, but it means I also can't handle them anymore.
I always get the following stack:
Unhandled error Network error: Response not successful: Received status code 500 Error: Network error: Response not successful: Received status code 500
at new ApolloError (webpack-internal:///./node_modules/apollo-client/errors/ApolloError.js:36:28)
at eval (webpack-internal:///./node_modules/apollo-client/core/QueryManager.js:287:41)
at eval (webpack-internal:///./node_modules/apollo-client/core/QueryManager.js:668:17)
at Array.forEach (<anonymous>)
at eval (webpack-internal:///./node_modules/apollo-client/core/QueryManager.js:667:18)
at Map.forEach (<anonymous>)
at QueryManager.broadcastQueries (webpack-internal:///./node_modules/apollo-client/core/QueryManager.js:662:22)
at eval (webpack-internal:///./node_modules/apollo-client/core/QueryManager.js:236:31)
at <anonymous>
For reference:
- apollo-client: 2.2.5
- react-apollo: 2.0.4
As described here:
I believe the way to "handle" the error when using the graphql HOC is
to simply check data.errors inside the component. There's a check
inside apollo-client that throws if data.errors isn't accessed.
The whole issue on GitHub where this comment was made has a very interesting discussion about the how's and why's. Most of the proposed solutions didn't work for me, especially the componentDidCatch, which, IMHO, was the cleanest alternative.
I could get over it touching the this.props.data.error, but I'm definitely not happy with it.
Edit
I've just noticed that you mentioned that the errors where happening when the component was unmounting... and well, it seems to be fixed on 2.1.0-beta.3. :-)

Angular UI router and $stateChangeError - strange resolve loop

The app I'm writing is using the resolve property in the main UI router state.
It tries to resolve to a list of things, using a factory that uses $http.
So I was trying to implement error handling, I changed my server to return a 404 status, and added thus lines:
$rootScope.$on('$stateChangeError', function(event) {
$state.go('404');
});
as Nate Abele explained here: Angular UI router handling 404s
Now the app do try to change the state to my 404 state, but a very strange loop occurred. The app keep trying to resolve the failed factory from the resolve property.
Haven't figured up why until now.
Any suggestions ? Thanks.

Angularjs 1.2.6 and 1.2.14 showing 1.2.5 error

I got this error message while i'm using angular 1.2.6 and tried 1.2.14 but the error message still showing.
`Uncaught Error: [$injector:modulerr]
http://errors.angularjs.org/1.2.5/$injector/modulerr?p0=app&p1=Error%3A%20%…
F1.2.5%2F%24injector%2Fnomod%3Fp0%3Dapp%0A%20%20%20%20at%20Error%20
(native...<omitted>...5) `
I already check my dependencies, I think there got nothing wrong.
The weird thing is my web app still running well with this error.
I FIGURED IT OUT.
It is error from chrome extension which written by angularjs !!!
Not my app error.
^#$%###$^&$%^#&$%&$#^&$%^

Refreshing page on backbone application causes error

I have a backbone application that displays a list of content. The application works fine when navigating through it using the links etc, but I have noticed that when I refresh the browser in chrome i start to see an error saying 'Uncaught TypeError: Cannot read property 'href' of null' This error is occurring on line 969 of backbone.js.
The code that is causing this error is being executed in a loop via a the following code :
this._checkUrlInterval = setInterval(this.checkUrl, this.interval);
Does anyone have any idea what is causing this? I am starting the backbone history using the following code :
Backbone.history.start();
My application is built with backbone, require.js and jquery mobile, however if I remove the jquery mobile dependancy I still see the same error so don't think it has anything to do with jquery mobile.
Any help would be greatly appreciated
Kind Regards
Brian

Resources