@adaas/a-utils 0.1.26 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaas/a-utils",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "description": "A-Utils is a set of utilities that are used across the ADAAS ecosystem. This package is designed to be a collection of utilities that are used across the ADAAS ecosystem.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.cjs",
@@ -16,6 +16,48 @@ import { A_Service_Error } from "./A-Service.error";
16
16
  export class A_Service extends A_Container {
17
17
 
18
18
 
19
+ @A_Concept.Load()
20
+ /**
21
+ * Load the service
22
+ */
23
+ async load() {
24
+ try {
25
+ await this.call(A_ServiceFeatures.onBeforeLoad);
26
+
27
+ await this.call(A_ServiceFeatures.onLoad);
28
+
29
+ await this.call(A_ServiceFeatures.onAfterLoad);
30
+
31
+ } catch (error) {
32
+
33
+ let wrappedError;
34
+
35
+ switch (true) {
36
+ case error instanceof A_Service_Error:
37
+ wrappedError = error;
38
+ break;
39
+
40
+ case error instanceof A_Error && error.originalError instanceof A_Service_Error:
41
+ wrappedError = error.originalError;
42
+ break;
43
+
44
+ default:
45
+ wrappedError = new A_Service_Error({
46
+ title: A_Service_Error.ServiceLoadError,
47
+ description: 'An error occurred while processing the request.',
48
+ originalError: error
49
+ })
50
+ break;
51
+ }
52
+
53
+ this.scope.register(wrappedError);
54
+
55
+ await this.call(A_ServiceFeatures.onError);
56
+ }
57
+
58
+ }
59
+
60
+
19
61
  @A_Concept.Start()
20
62
  /**
21
63
  * Start the server
@@ -97,6 +139,9 @@ export class A_Service extends A_Container {
97
139
  }
98
140
  }
99
141
 
142
+
143
+
144
+
100
145
  // ======================================================================================
101
146
  // ============================= A-Service Lifecycle =================================
102
147
  // ======================================================================================
@@ -104,6 +149,7 @@ export class A_Service extends A_Container {
104
149
  @A_Feature.Extend()
105
150
  protected async [A_ServiceFeatures.onBeforeLoad](
106
151
  @A_Inject(A_Polyfill) polyfill: A_Polyfill,
152
+ ...args: any[]
107
153
  ): Promise<void> {
108
154
  // Initialize Polyfill
109
155
  if (!polyfill) {
@@ -147,7 +193,8 @@ export class A_Service extends A_Container {
147
193
  protected async [A_ServiceFeatures.onError](
148
194
  @A_Inject(A_Error) error: A_Error,
149
195
  @A_Inject(A_Logger) logger?: A_Logger,
150
- ...args: any[]) {
196
+ ...args: any[]
197
+ ) {
151
198
  logger?.error(error);
152
199
  }
153
200
 
@@ -4,8 +4,12 @@ import { A_Error } from "@adaas/a-concept";
4
4
 
5
5
  export class A_Service_Error extends A_Error {
6
6
 
7
+ static readonly ServiceLoadError = 'Service load error';
8
+
7
9
  static readonly ServiceStartError = 'Service start error';
8
10
 
9
11
  static readonly ServiceStopError = 'Service stop error';
10
12
 
13
+
14
+
11
15
  }