I have written some Javascript code to load an image (uploaded by the end user) which looks as follows :
var img = new Image;
var ctx = _this.canvas.getContext('2d');
img.onload = function(){
ctx.drawImage(img, 0, 0, img.width, img.height);
//do other stuff..
}
img.onerror = function(event){
bootbox.alert("Error loading the image!");
}
img.src = Settings.URL + '/images/loadimage/?imageKey=' + imageKey;
Server returns 404 response if the image corresponding to the imageKey
does not exist, it also returns error 500 in other error scenarios.
This code works fine, but what I want to do is to show two different messages in the following two different cases:
- When I get 404 response.
- When Error 500 response.
What I am not able to figure out is - how to get response code in img.onerror
.