I want to handle de 404 error in console. The red ones.
I know that if I do something like
if (http.readyState === 4) {
if (http.status === 400) {
//some code
}
}
I will handle the error, but in the consele, it will appear in red. That is the errot taht I want to avoid.
Utils.js:701 GET http://url/url/id.pdf 404 (Not Found)
You can handle the error with a http.status === 404 or with a try... catch sentence.
However, you can't supress the red message on the chrome's console:
Suppress Chrome 'Failed to load resource' messages in console
The best you can do is console.clear(); when handling the error, but that dosn't work always.
There is no way to stop the 404 error message from being displayed inside the browser console.
However, if it is your own server that you are requesting, you can have another request checking for the existence of your file before you request the file, that way you can avoid the 404 error
Related
So the problem is when I try to initiate a new WebSocket to a remote host, sometimes the browser's console prints a red error message and complains about a refused connection, here is the message:
Error in connection establishment: net::ERR_CONNECTION_REFUSED
Having an error is fine since the remote host might be not responding sometimes, but the fact that I cannot handle this error message is very annoying.
Is there any way to either handle this error message or check whether the remote host accepts the WebSocket connection before initializing one in my JavaScript code??
Several possibilities come to mind:
Add a WebSocket.onerror error handler
myWebSocket.onerror = myEventHandler;
Wrap your "connect" in a try/catch block
try {
const connection = new WebSocket(myUrl);
...
}
catch(error) {
console.error(error);
}
Structure your code such that your I/O is event driven:
https://developer.mozilla.org/en-US/docs/Web/API/WebSocket#Examples
// Create WebSocket connection.
const socket = new WebSocket('ws://localhost:8080');
// Connection opened
socket.addEventListener('open', function (event) {
socket.send('Hello Server!');
});
// Listen for messages
socket.addEventListener('message', function (event) {
console.log('Message from server ', event.data);
});
// Handle errors
socket.addEventListener('error', function (event) {
console.log('WebSocket error observed:', event);
});
ADDENDUM:
The above methods allow you to completely handle a websockets exception.
Regardless of whether the exception is handled or not, the Chrome debugger will tell you if an exception has occurred. This is a Good Thing. It's called a "First-Chance Exception":
https://learn.microsoft.com/en-us/security-risk-detection/concepts/first-chance-exception
.. it is known a “first chance” exception – the debugger is given the
first chance of inspecting the exception prior to the application
handling it (or not).
In Microsoft's Visual Studio debugger, there's a little checkbox you can use to "gag" first chance exceptions. I'm not aware of any similar "checkbox" in Chrome debugger.
POSSIBLE SUGGESTIONS:
Chrome debugger has a "filter". EXAMPLE FILTER REGEX: ^((?!ERR_CONNECTION_REFUSED).)*$
This link suggests you might be able to use the filter to "Hide Network Messages" (I haven't tried it myself). See also this link.
When a user signs up, I am requiring them to verify their email address.
It works fine in Firefox and Chrome, but not in Safari, where I get the following message:
Error: A network error (such as timeout, interrupted connection or unreachable host) has occurred.
And no confirmation email is sent.
I’m sourcing this version:
firebasejs/6.4.0/firebase-auth.js
I've searched for similar problems. There were lots of Firebase Authentication errors, but I didn't find this one.
Using the Safari JavaScript debugger, filtering for all exceptions I receive the errors below.
And interestingly, after stepping through with the debugger on, setting Breakpoints at "All Exceptions" an email is sent. But not when running in real-time.
Hopefully that is a clue.
I send the email verification with this code.
if (current_user && !current_user.emailVerified) {
current_user.sendEmailVerification().then(function() {
const user_message = '<message to user>';
window.location = '/message?message=' + user_message;
}).catch((error) => {
console.log(error);
} );
}
The errors:
line 515 rpchandler.js
try {
response = JSON.parse(this.getResponseText()) || null;
It looks like the response is null.
line 183 promise.js Exception with thrown value: zi
try {
// Promise was rejected. Step up one call frame to see why.
if (reason instanceof Error) {
throw reason;
This happens a few times.
line 2190 authuser.js
// Cache the invalidation error.
self.userInvalidatedError_ = /** #type {!fireauth.AuthError} */ (error);
line 740 firebase-app.js
Exception with thrown value: TypeError: Argument to String.prototype.startsWith cannot be a RegExp
Any ideas?
I ended up rolling my own email verification workflow.
I'd be interested in reverting back to the Firebase Auth JavaScript email verification workflow, if there is a solution. But for now, I just have to move forward.
I have triggering an Ajax call and in the error callback I am trying to access the exception message(Not the Response Text). I am throwing an exception like this:
throw new Exception("Please enter a response")
Now I want to get the above message and display it in alert box.
I searched stackoverflow and found this:
error: function(e,status){
var err = eval("(" + e.responseText + ")");
alert(err.Message);
}
but the above doesn't work.
I am getting the response text but not able to access that particular message.
The error that I am getting is Uncaught SyntaxError: Unexpected token <
When your server throws an Internal Server Error, from Javascript side it's still a succes. how about adding the Status code response instead of throwing exception from the backend
return new HttpStatusCodeResult(400, "Custom Error Message 2");
You can refer this and try to get error message as alert(err.message); (lowercase) not alert(err.Message);
Is it possible to catch the browser error when
socket = new WebSocket(WSHost);
fails and try .. catch doesn't work?
Check this jsfiddle and open browser console (F12) and click connect:
http://jsfiddle.net/gsz4kpw4/15/
the "socket.onerror" fires, but there is no error message inside the error event. The browser is logging the message to it's console. Any one know a possibility to catch this message and output with alert?
I also tried this:
function yourCustomLog(msg) {
alert(msg);
}
window.console= yourCustomLog;
But it seems that the browser websocket connect error isn't a real console error. There is no alert when the error occurs.
I want to catch a specific failure of this JavaScript code:
var script = $wnd.document.createElement('script');
script.setAttribute('src', url);
script.setAttribute('type', 'text/javascript');
When the url where the script resides needs the user to be logged in, and so returns an HTTP 401 Unauthorized error.
None of the values I understand that error (in a try/catch) can take on seem to match very well.
EvalError: An error in the eval() function has occurred.
RangeError: Out of range number value has occurred.
ReferenceError: An illegal reference has occurred.
SyntaxError: A syntax error within code inside the eval() function has occurred. event.
TypeError: An error in the expected variable type has occurred.
URIError: An error when encoding or decoding the URI has occurred (ie: when calling encodeURI()).
Is there any way to catch specifically this 401 error, or at least the class of IO error that would be thrown by not being able to load the script.
Thanks
script.addEventListener('error', function(){
// Didn't load
}, true);