Skip to content

Commit

Permalink
ENG-0000 - Event for API Errors
Browse files Browse the repository at this point in the history
`AlDefaultClient` now emits an event to its notification stream in the
case of API errors.
  • Loading branch information
mcnielsen committed Aug 11, 2022
1 parent a54107b commit 8d52f1d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@al/core",
"version": "1.0.189",
"version": "1.0.190",
"description": "Node Enterprise Packages for Alert Logic (NEPAL) Core Library",
"main": "./dist/index.cjs.js",
"types": "./dist/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/client/al-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
AlInterceptionRule,
AlInterceptionRules,
} from './types';
import { AlClientBeforeRequestEvent } from './events';
import { AlClientBeforeRequestEvent, AlClientAPIErrorEvent } from './events';
import { AIMSSessionDescriptor } from '../aims-client/types';
import { AlRuntimeConfiguration, ConfigOption } from '../configuration';
import { commonTypeSchematics } from './common.schematics';
Expand Down Expand Up @@ -975,6 +975,7 @@ export class AlApiClient implements AlValidationSchemaProvider
data: errorResponse.data
};
this.log( `APIClient Failed Request Snapshot: ${JSON.stringify( snapshot, null, 4 )}` );
this.events.trigger( new AlClientAPIErrorEvent( errorResponse.config, errorResponse ) );
return Promise.reject( errorResponse );
}

Expand Down
10 changes: 9 additions & 1 deletion src/client/events/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AxiosRequestConfig } from 'axios';
import { AxiosRequestConfig, AxiosResponse } from 'axios';
import {
AlTrigger,
AlTriggeredEvent,
Expand All @@ -12,3 +12,11 @@ export class AlClientBeforeRequestEvent extends AlTriggeredEvent<void>
super();
}
}

@AlTrigger( 'AlClientAPIError' )
export class AlClientAPIErrorEvent extends AlTriggeredEvent<void>
{
constructor( public request:APIRequestParams, public errorResponse:AxiosResponse ) {
super();
}
}

0 comments on commit 8d52f1d

Please sign in to comment.