-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrequireService.ts
More file actions
22 lines (20 loc) · 690 Bytes
/
requireService.ts
File metadata and controls
22 lines (20 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { ServiceIsNotDefinedException } from "../exception";
/**
* Ensures that a service is defined.
*
* @param {T | null | undefined} service The service object to check.
* @param {string} [message="Service is not defined."] The error message to throw if the service is not defined.
* @returns {T} The service object.
* @throws {ServiceIsNotDefinedException} If the service is null or undefined.
* @since 1.5.0
* @template T
*/
export function requireService<T>(
service: T | null | undefined,
message: string = "Service is not defined."
): T {
if (service === null || service === undefined) {
throw new ServiceIsNotDefinedException(message);
}
return service;
}