使用Golang服务器是否可以对AngularJS发布请求发出失败?

I have a HTTP server written in golang and the client is written in AngularJs. The client will send a POST request to the server with username/password to attempt to register a new account. I want the client to do something depending on the answer of the server. If a user with the requested username already exists I want to stay at the registration site, else I want the client to change the view to something else.

I have the follow code to POST to the server, but how do I tell the client that the request failed?

$scope.register = function(){
    var postBody = JSON.stringify({username:$scope.vm.user.username, password:$scope.vm.user.password})

    Registration.save(postBody, function(data){
        //on success
        console.log(data)
        //$location.path('/bookingsystem')
    });     
};

Assuming that you are using $resource to create Registration you can do

Registration.save(postBody, function(data, responseHeaders){
    //on success
    console.log(data)
    console.log(responseHeaders)
    //$location.path('/bookingsystem')
}, function(httpResponse){
    // Handle the error
    console.log(httpResponse)
}); 

See the documentation on $resource for more API documentation.