All files / utils/container/error ServiceNotFoundError.ts

18.18% Statements 2/11
0% Branches 0/8
0% Functions 0/1
18.18% Lines 2/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  8x         8x                                            
import { ServiceIdentifier } from '../types/ServiceIdentifier';
import { Token } from '../Token';
 
/**
 * Thrown when requested service was not found.
 */
export class ServiceNotFoundError extends Error {
    name = 'ServiceNotFoundError';
 
    constructor(identifier: ServiceIdentifier) {
        super();
 
        if (typeof identifier === 'string') {
            this.message = `Service '${identifier}' was not found, looks like it was not registered in the container. ` +
                `Register it by calling Container.set('${identifier}', ...) before using service.`;
 
        } else if (identifier instanceof Token && identifier.name) {
            this.message = `Service '${identifier.name}' was not found, looks like it was not registered in the container. ` +
                `Register it by calling Container.set before using service.`;
 
        } else if (identifier instanceof Token) {
            this.message = `Service with a given token was not found, looks like it was not registered in the container. ` +
                `Register it by calling Container.set before using service.`;
        }
 
        Object.setPrototypeOf(this, ServiceNotFoundError.prototype);
    }
 
}