An Angularjs module for logging client side javascript errors

Added by: Sam Deering





Stars: 0

Watchers: 0

Forks: 0

Module Description


An Angularjs module for logging http and js errors to a MYSQL database using PHP Slim

###Example ####HTML

<button class="btn btn-primary" ng-click="app.make_error()">Throw an error</button>
<form ng-submit="app.get_errors(error_id)" style="margin: 21px 0px;">
    <div class="form-group">
        <label>Error id</label>
        <input type="text" class="form-control" ng-model="error_id" />
    <input type="submit" class="btn btn-primary" value="Get error records" />


]).controller('AppCtlr', ['logError', function (logError){
    var self = this;
    this.logError = logError;
    this.error_records = {};
    this.get_errors = function(id){
            var object = Utility.parse_json(res);
            self.error_records = object;
    this.make_error = function(){
        throw new Error('This is an error.');


  • error_endpoint - The url path to the phpSlim index.php file. The phpSlim application can be used for the API or a url to point to an existing API can be used. This should be defined in a constant named 'CONF' with 'error_endpoint':'/bower_components/ckc-angularjs-errors/error'

###Angular Methods

  • .post(exception(exception object or json string), cause(string))
  • .get(id(integer of database record id))

###API Methods

  • isJson(string) - Returns decoded json if valid, else returns json error

  • create_SQL(array) - Creates an insert SQL string from the below array 'fields'=>array( 'key'=>'value' ), 'model'=>'table_name'

  • read_SQL(array) - Creates a select SQL string from the below array 'conditions'=>array( 'key'=>'value', 'IN'=>array( 'key'=>'value', 'key'=>'value' ) ), 'fields'=>array('key'), 'model'=>'table_name', 'limit'=>'integer', 'order'=>'key', 'direction'=>'default:DESC'

  • update_SQL(array) - Creates an update SQL string from the below array 'conditions'=>array( 'key'=>'value', 'IN'=>array( 'key'=>'value', 'key'=>'value' ) ), 'fields'=>array( 'key'=>'value'), 'model'=>'table_name'

  • delete_SQL(array) - Creates a delete SQL string from the below array 'conditions'=>array( 'key'=>'value', 'IN'=>array( 'key'=>'value', 'key'=>'value' ) ), 'model'=>'table_name'

  • total(string) - Returns the number of rows from supplied SQL string

  • fields(string) - Returns the columns names of a supplied table name

  • create(string) - Returns 1 if a create is successful from supplied SQL string

  • read(string) - Returns the rows from supplied SQL string

  • update(string) - Returns 1 if an update is successful from supplied SQL string

  • delete(string) - Returns 1 if a delete is successful from supplied SQL string

###API End-points

  • /error (POST) - Adds a record for an error. There is a check to see if the user, based on a php session, has generated an error with the same data in a period of 1 second and only creates a record if they have not
  • /error (GET) - Gets all errors
  • /error/id (GET) - Gets a specific error record based on an id


  • Bower - ckc-angularjs-errors
  • Add "error_module" to your app's dependencies
  • Add "js/dist/errors.min.js" to your scripts
  • Add 'CONF' constant with 'error_endpoint':'/bower_components/ckc-angularjs-errors/error' or a custom url to the API endpoint of your choice
  • Config databases in a file named "ckc-angularjs-errors-config.php" just outside the bower folder. In here you can also require additional custom models
  • Run composer install just inside the bower package. This installs the necessary PHP packages

Module stats last updated: 2015-04-19 02:00:54

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!