Capturing HTTP Errors in Javascript

Using Javascript, how do I check the server response code?
For example if following code failed, say, with 403 (rate limit exceeded) how would I modify the code to capture the error?
key: ‘xxx’,
locations: ‘0.76804,51.8284:0.87616,51.8091’

calculateRoute returns a Promise, so you can do it that way:{
    key: 'xxx',
    locations: '0.76804,51.8284:0.87616,51.8091'
.then(function(response) {
.catch(function(err) {

THANK YOU. Exactly what I wanted.