All files / utils exception.ts

100% Statements 8/8
100% Branches 8/8
100% Functions 4/4
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 256x   79x 6x         69x 4x         176591x 4x         176651x        
export class Exception {
  static throwIfNull(value: any, valueDescription: ExceptionValueDescription) {
    if (value == null) {
      throw `${valueDescription} property cannot be set to null`;
    }
  }
 
  static throwIfNegative(value: number, valueDescription: ExceptionValueDescription) {
    if (value < 0) {
      throw `${valueDescription} property cannot be set to a negative number (${value})`;
    }
  }
 
  static throwIfNotBetween(value: number, valueDescription: ExceptionValueDescription, rangeFrom: number, rangeTo: number) {
    if(value < rangeFrom || value > rangeTo) {
      throw `Seek expects a value between ${rangeFrom} and ${rangeTo}`;
    }
  }
 
  static getDescriptionForProperty(className: string, methodName: string): ExceptionValueDescription {
    return `${className}'s ${methodName}`;
  }
}
 
export type ExceptionValueDescription = string;