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?
tt.services.calculateRoute(
{
key: ‘xxx’,
locations: ‘0.76804,51.8284:0.87616,51.8091’
})
.then(function(response)
{
});

calculateRoute returns a Promise, so you can do it that way:

tt.services.calculateRoute({
    key: 'xxx',
    locations: '0.76804,51.8284:0.87616,51.8091'
})
.then(function(response) {
})
.catch(function(err) {
    console.log(err)
);

THANK YOU. Exactly what I wanted.