twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

error_classes.js (828B)


      1 'use strict';
      2 
      3 var resolve = require('./resolve');
      4 
      5 module.exports = {
      6   Validation: errorSubclass(ValidationError),
      7   MissingRef: errorSubclass(MissingRefError)
      8 };
      9 
     10 
     11 function ValidationError(errors) {
     12   this.message = 'validation failed';
     13   this.errors = errors;
     14   this.ajv = this.validation = true;
     15 }
     16 
     17 
     18 MissingRefError.message = function (baseId, ref) {
     19   return 'can\'t resolve reference ' + ref + ' from id ' + baseId;
     20 };
     21 
     22 
     23 function MissingRefError(baseId, ref, message) {
     24   this.message = message || MissingRefError.message(baseId, ref);
     25   this.missingRef = resolve.url(baseId, ref);
     26   this.missingSchema = resolve.normalizeId(resolve.fullPath(this.missingRef));
     27 }
     28 
     29 
     30 function errorSubclass(Subclass) {
     31   Subclass.prototype = Object.create(Error.prototype);
     32   Subclass.prototype.constructor = Subclass;
     33   return Subclass;
     34 }