Skip to content

Commit 9abe619

Browse files
committed
Add special error class for idempotency key reuse
Signed-off-by: Andrew Richardson <[email protected]>
1 parent a1b2d91 commit 9abe619

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

lib/http.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
FireFlyReplaceOptions,
99
FireFlyUpdateOptions,
1010
FireFlyDeleteOptions,
11+
FireFlyIdempotencyError,
1112
} from './interfaces';
1213

1314
function isSuccess(status: number) {
@@ -74,8 +75,12 @@ export default class HttpBase {
7475
protected async wrapError<T>(response: Promise<AxiosResponse<T>>) {
7576
return response.catch((err) => {
7677
if (axios.isAxiosError(err)) {
77-
const errorMessage = err.response?.data?.error;
78-
const ffError = new FireFlyError(errorMessage ?? err.message, err, err.request.path);
78+
const errorMessage = err.response?.data?.error ?? err.message;
79+
const errorClass =
80+
errorMessage?.includes('FF10430') || errorMessage?.includes('FF10431')
81+
? FireFlyIdempotencyError
82+
: FireFlyError;
83+
const ffError = new errorClass(errorMessage, err, err.request.path);
7984
if (this.errorHandler !== undefined) {
8085
this.errorHandler(ffError);
8186
}

lib/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export class FireFlyError extends Error {
2121
}
2222
}
2323

24+
export class FireFlyIdempotencyError extends FireFlyError {}
25+
2426
interface FireFlyBaseHttpOptions {
2527
requestConfig?: AxiosRequestConfig;
2628
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hyperledger/firefly-sdk",
3-
"version": "1.2.6",
3+
"version": "1.2.7",
44
"description": "Client SDK for Hyperledger FireFly",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)