The example below shows how getStatusCode method can be used to make invocation time decisions on an endpoint’s availability and act accordingly. Similarly, you can utilize received status codes of HTTP endpoints as an effective way of hardening your program when it’s appropriate.
To try out the example create the folder structure <BALLERINA_HOME>/statuscode/sample and then create ballerina files with the content of the two gists. Package the services into a bsz archive and run it. Invoke /proxy service with a header "CONTROLLER: faulty backend" to simulate an server side error.
curl -X GET -v http://localhost:9090/proxy -H "CONTROLLER: faulty backend"
find out more about ballerina here: http://ballerinalang.org
Note: this example was written for ballerina 0.86 and may not work with other versions.