Hi,
The response object contains also the status code as a number. In your sample, you should be able to retrieve it with something like (after line 12):
var status = response.statusCode; if (status >= 400) { System.log("Got an error status code"); } else { // ... }