Skip to content

Commit 8d52f1d

Browse files
committed
ENG-0000 - Event for API Errors
`AlDefaultClient` now emits an event to its notification stream in the case of API errors.
1 parent a54107b commit 8d52f1d

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@al/core",
3-
"version": "1.0.189",
3+
"version": "1.0.190",
44
"description": "Node Enterprise Packages for Alert Logic (NEPAL) Core Library",
55
"main": "./dist/index.cjs.js",
66
"types": "./dist/index.d.ts",

src/client/al-api-client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import {
5454
AlInterceptionRule,
5555
AlInterceptionRules,
5656
} from './types';
57-
import { AlClientBeforeRequestEvent } from './events';
57+
import { AlClientBeforeRequestEvent, AlClientAPIErrorEvent } from './events';
5858
import { AIMSSessionDescriptor } from '../aims-client/types';
5959
import { AlRuntimeConfiguration, ConfigOption } from '../configuration';
6060
import { commonTypeSchematics } from './common.schematics';
@@ -975,6 +975,7 @@ export class AlApiClient implements AlValidationSchemaProvider
975975
data: errorResponse.data
976976
};
977977
this.log( `APIClient Failed Request Snapshot: ${JSON.stringify( snapshot, null, 4 )}` );
978+
this.events.trigger( new AlClientAPIErrorEvent( errorResponse.config, errorResponse ) );
978979
return Promise.reject( errorResponse );
979980
}
980981

src/client/events/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AxiosRequestConfig } from 'axios';
1+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
22
import {
33
AlTrigger,
44
AlTriggeredEvent,
@@ -12,3 +12,11 @@ export class AlClientBeforeRequestEvent extends AlTriggeredEvent<void>
1212
super();
1313
}
1414
}
15+
16+
@AlTrigger( 'AlClientAPIError' )
17+
export class AlClientAPIErrorEvent extends AlTriggeredEvent<void>
18+
{
19+
constructor( public request:APIRequestParams, public errorResponse:AxiosResponse ) {
20+
super();
21+
}
22+
}

0 commit comments

Comments
 (0)