Handle error status codes in javascript