I try to eleminate an 404 error occuring because the source (src) is missing..
var $chart = $("<img />")
.addClass("trend-pic")
.error(function(){
console.log("error loading..")
});
try{
$chart.attr("src", jobs[counter].url + "test/trend")
}catch(err){
$chart.attr("src", "");
}
if tried many stuff to catch the error i.e. putting an .error(function(){}) at the end.
use the $chart.load() - method to check if the images gets loaded?
Non of those helped?
GET {myURLString} 404 (Not Found)
Browser: Safari
You can't really delete those 404 errors from the console.
The best you can do is make some ajax calls and see the return code, but then you'll be limited to request only to your own domain.
EDIT--
Oh, and yes, those errors will keep showing in the "Requests" tab! They just won't appear in the "Console" tab (in Chrome).
I think there is no way to eliminate the error from your console, except using the right url.
In your code with the try {} catch() the error is thrown and $chart.attr will be called again with an empty string.
What you can do is add a check like this before you set the .attr()
if (jobs[counter].url !== void 0 &&
jobs[counter].url.length !== 0) {
$chart.attr("src", jobs[counter].url + "test/trend")
}
so you can remove the try{} catch()
Hope it helps.
Just the answer is No.Because this is the only way Server send "there is a Error".
Refer this one.
Prevent 404 Error in console
404 is not an error. It is the way server says it does not have the source referred by the client.
Related
I open a file download from a remote API on my webpage via window.open(). The API (a Flask server) has error handling and returns the error message if there's an internal server error, like this:
#app.errorhandler(502) //all other errors are handled the same way, including 500, etc.
#crossdomain(origin='*')
def bad_gateway_error(error):
return "Bad Gateway Error - Please make sure you're using a properly formatted file! Details: " + str(error), 200
I want to display this error on my site instead of redirecting to the error page. I'm trying to catch it via:
try {
window.open("https://API/receivedoc?timestamp="+timestamp,"_self")
} catch(e) {
filerootdiv.querySelector('.output').innerHTML = String(e);
}
This however does nothing (tested in Chrome). How could I catch the error when I'm using window.open? I guess it might be because in the error handling I return a 200 message so that the string I return actually gets returned instead of just crashing the server (this needs to stay this way as it's working just fine with all the other errors when I'm not trying to return a file). The issue is that I can't tell if the API request would return a file or a string before doing a window.open().
UPDATE
I've tried implementing:
let new_window = window.open("https://flaskmin.run.aws-usw02-pr.ice.predix.io/receivedoc?timestamp="+timestamp,"_self")
newWindow.onerror = function() {
filerootdiv.querySelector('.output').innerHTML = "Error!";
However this still only opens a new window with the error. I guess it's because of the error handling on the server side (I cannot change this). Can I somehow probe the content of new_window before redirecting to it, and just not open it if it's just a string containing the word 'error'?
I have html page which causes js error and an global handler for it.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
$(function () {
window.onerror = function (errorMsg, url, lineNumber) {
alert('Error: ' + errorMsg + ' Script: ' + url + ' Line: ' + lineNumber);
}
throw new Error("this is error");
});
</script>
</head>
<body>
<div>Test page</div>
</body>
</html>
I receive alert: "Error: Script error. Script: Line: 0". As you can see error info is missing. How can I get this info here like I can see errors in developer tools. Any extensions for chrome are not suitable. I must catch errors with their info in javascript.
When a syntax(?) error occurs in a script, loaded from a different origin, the details of the syntax error are not reported to prevent leaking information (see bug 363897). Instead the error reported is simply "Script error." This behavior can be overriden in some browsers using the crossorigin attribute on and having the server send the appropriate CORS HTTP response headers. A workaround is to isolate "Script error." and handle it knowing that the error detail is only viewable in the browser console and not accessible via JavaScript.
I also ran into this. See notes section here: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
This implies the development setup might need some adjustment to avoid this policy issue. I'm merely guessing here, so don't take it for granted.
I am just adding answer for the sake of those who came here looking.
Source: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
Please go this URL, as you can see there are five parameters to
window.onerror = function(message, source, lineno, colno, error) { ... }
the last one is the one you need, it has complete record of what you see in console in case of error.
message: error message (string). Available as event (sic!) in HTML onerror="" handler.
source: URL of the script where the error was raised (string)
lineno: Line number where error was raised (number)
colno: Column number for the line where the error occurred (number)
error: Error Object (object)
Then Error Object has two properties
message
stack
stack is the one which will contain all the information you required.
use console.log(errorMsg, url, lineNumber)instead of alert to get more readable log. You can see the log in browser developer console. Also you can check the use of try..catch for better error handling.
use jquery script with anonymous attirbute, and the script server response header with [access-control-allow-origin:*]. Your error throw code is runned with jquery callback.
errorMsg is NOT the message "this is error"; it is Script error., which is precisely what you're seeing. You simply don't get the error message that way. onerror is unsuited to replace a try-catch block.
When I have uncaught errors in my angular applications the console message looks like this:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.3/$injector/modulerr?p0=app&p1=%5B%24injector%3Aunpr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.4.3%2F%24injector%2Funpr%3Fp0%3DENVIRONMENT%0AJ%2F%3C%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A11%3A416%0Aeb%2Fr.%24injector%3C%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A45%3A375%0Ad%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A43%3A364%0A%40http%3A%2F%2Flocalhost%3A8600%2Fapp%2Fapp.js%3A42%3A18%0Ae%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A44%3A154%0Ad%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A42%3A320%0Ag%2F%3C%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A42%3A452%0Am%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A12%3A320%0Ag%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A42%3A229%0Aeb%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A45%3A1%0AAc%2Fd%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A24%3A339%0AAc%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A25%3A151%0AZd%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A23%3A464%0A%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A294%3A428%0An.Callbacks%2Fj%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A2%3A26920%0An.Callbacks%2Fk.fireWith%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A2%3A27738%0A.ready%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A2%3A29530%0AI%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A2%3A29721%0AnrWrapper%40http%3A%2F%2Flocalhost%3A8600%2F%23%2Fdashboard%3A15%3A12749%0A
Which is not useful, but if I url_decode it it is much better, like this:
http://errors.angularjs.org/1.4.3/$injector/modulerr?p0=app&p1=[$injector:unpr] http://errors.angularjs.org/1.4.3/$injector/unpr?p0=ENVIRONMENT
J/<#http://localhost:8600/libs.js:11:416
eb/r.$injector<#http://localhost:8600/libs.js:45:375
d#http://localhost:8600/libs.js:43:364
#http://localhost:8600/app/app.js:42:18
e#http://localhost:8600/libs.js:44:154
d#http://localhost:8600/libs.js:42:320
g/<#http://localhost:8600/libs.js:42:452
m#http://localhost:8600/libs.js:12:320
g#http://localhost:8600/libs.js:42:229
eb#http://localhost:8600/libs.js:45:1
Ac/d#http://localhost:8600/libs.js:24:339
Ac#http://localhost:8600/libs.js:25:151
Zd#http://localhost:8600/libs.js:23:464
#http://localhost:8600/libs.js:294:428
n.Callbacks/j#http://localhost:8600/libs.js:2:26920
n.Callbacks/k.fireWith#http://localhost:8600/libs.js:2:27738
.ready#http://localhost:8600/libs.js:2:29530
I#http://localhost:8600/libs.js:2:29721
nrWrapper#http://localhost:8600/#/dashboard:15:12749
How can I get angular to output errors this way by default? Thanks.
It's url encoded because it's a link. Click it! :D
It will bring you to a webpage that explains the error.
This is your error
If you go to that page and look at the error it will say that it threw an error because of x error. Then that error will be a link to, so click that as well.
And now that you've gotten to that last page, the error is that you have an unknown provider called ENVIRONMENT.
You can override exception handler:
angular.module('exceptionOverride', []).factory('$exceptionHandler', function() {
return function(exception, cause) {
exception.message += ' (caused by "' + cause + '")';
throw exception;
};
});
More here
I am getting an error which seems to be originating from one of the page scripts.
file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1
return c.apply(undefined,a)}catch(d){webengage.eLog(d);if(!b){throw d}}}else{t
^
TypeError: Cannot call method 'call' of undefined
at new exports.NOT_IMPLEMENTED (/usr/local/lib/node_modules/jsdom/lib/jsdom/browser/utils.js:9:13)
at Object.webengage.eLog (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:366)
at t.extend.u (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:19160)
at Object.t.extend.error (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:19299)
at file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:66518
at Object.webengage.withELog (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:640)
at Timer.<anonymous> (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:937)
at Timer.exports.setInterval.timer.ontimeout (timers.js:234:14)
I am getting this error from the following code:
try {
var document = jsdom.jsdom(str, null, {});
} catch(e) {
console.log("Got ERROR...");
console.log(e);
}
console.log("Page Document Loaded.");
var window = document.parentWindow;
//console.log(window.document.innerHTML);
console.log(window.innerWidth);
console.log(typeof window.document.getElementsByClassName);
here str is the html that i got earlier. I am able to see printed results, the html the innerWidth and the typeof getElementsByClassName i.e.. function. But after around 20 seconds i am getting the above error and my application crashes, without printing Got ERROR... from above.
The first question that i have is why is my application still running after printing the last thing. Is this a normal behavior for jsdom that it keeps on running like how in a browser a script keeps on running until window.close() is given.
The actual problem is, how can i resolve this. I want to trigger few events in this window object and interact with it but it keeps on crashing.
The url for the script is a little confusing:
file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1
this is because the page is fetching this script resource in an ajax call with the url:
//cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1
although jsdom is able to get the resource, i checked that this script has that line where it is showing the error.
function getViews(){
$.get (
"http://www.roblox.com/User.aspx?ID=16",
function parse(data) {
var userviews = $(data).find("#ctl00_cphRoblox_rbxUserStatisticsPane_lProfileViewsStatistics").html();
alert(userviews);
}
);
}
getViews();
I basically want it to do the same thing as the line below, except there's more to my jquery function that I didnt give because I know that works:
alert(document.getElementById('ctl00_cphRoblox_rbxUserStatisticsPane_lProfileViewsStatistics').innerHTML)
You don't give details but I suspect your success callback is not even executing (i.e., the alert() is not firing) because the AJAX request is failing. Your code will possibly not work unless it's hosted at http://www.roblox.com.
I can see the following error in the browser console:
XMLHttpRequest cannot load http://www.roblox.com/User.aspx?ID=16.
Origin http://test.local is not allowed by Access-Control-Allow-Origin.
In Firebug, Chrome and recent IE you can open the console with F12. In Firefox you can use Ctrl+Shift+K.