This is the code for an AngularJS controller that I've written:app.controller('employeeController', function (employeeService) {    var Controller = this;    Controller.employees = {};    Controller.fetchedEmployee = {};    Controller.populateTable = function (data) {        Controller.employees = data;    };    Controller.error = function (errorResponse) {        console.log(error function called.);        console.log(errorResponse);        // Request Errors        if(errorResponse.status === 400) alert(Error:  + errorResponse.data.error + : There was a problem with the data you submitted. \nPlease enter valid form data.);        else if(errorResponse.status === 401) alert(Error:  + errorResponse.data.error + : You need to provide proper authorization credentials to continue.);        else if(errorResponse.status === 403) alert(Error:  + errorResponse.data.error + : You are not allowed to perform this action.);        else if(errorResponse.status === 404) alert(Error:  + errorResponse.data.error + : The requested file or resource was not found.);        else if(errorResponse.status === 408) alert(Error:  + errorResponse.data.error + : The connection timed out. Please try again later.);        else if(errorResponse.status === 410) alert(Error:  + errorResponse.data.error + : The requested resource is no longer available.);        else if(errorResponse.status === 418) alert(Error:  + errorResponse.data.error + : I'm a teapot, not a coffeepot.);        // Server Errors        else if(errorResponse.status === 500) {            if(errorResponse.data.exception === java.sql.SQLException) alert(Error establishing connection with database. Please try again later.);            else alert(Error:  + errorResponse.data.error + : Generic Server Error.);        }    };    Controller.deleteEmployee = function(id) {        employeeService.getEmployee(id).then(function(data) {            Controller.fetchedEmployee = data.empInfo;            var reallyDelete = confirm(Do you really want to delete  + Controller.fetchedEmployee.employeeName + ?);            console.log(reallyDelete);            if(reallyDelete === true) employeeService.deleteEmployee(id);        }, Controller.error);    };    // Call Service to List all Employees    console.log(Service called to populate table.);    employeeService.getAllEmployees().then(Controller.populateTable, Controller.error);    Controller.populateTable();});Not that this code hasn't gone through improvements; initially it was full of this.something or even worse, $scope.something (scope soup), which made it difficult to understand and even resulted in some of the code being broken.However, it still feels sloppy. It feels like all the functions and variables have been 'injected' randomly in the controller; like someone randomly putting playing cards in a neatly shuffled deck or randomly placing books in a bookshelf.Could anyone help me devise a methodology to organize this code to have a definite structure?
AngularJS controller to fetch and display employee data from database
javascript;angular.js;controller