handle error response in javascript