From fcfc3cb1076baaa6e5949cfd3c7b0eeb317147bf Mon Sep 17 00:00:00 2001 From: Waradu Date: Sat, 10 May 2025 17:34:29 +0200 Subject: [PATCH] feat: return undefined if not found --- package.json | 2 +- src/index.d.ts | 2 +- src/index.js | 23 +++++++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 8e223d7..64b5762 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wirekvs-js", - "version": "2.0.0", + "version": "3.0.0", "description": "A Node.js client for the WireKVS database service", "main": "src/index.js", "types": "src/index.d.ts", diff --git a/src/index.d.ts b/src/index.d.ts index e8362f0..f9bd4b8 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -49,7 +49,7 @@ export class WireKVSDatabase extends EventEmitter { disconnect(): void; getAllEntries(): Promise; - get(key: string): Promise; + get(key: string): Promise; set(key: string, value: any): Promise; update(key: string, value: any): Promise; delete(key: string): Promise; diff --git a/src/index.js b/src/index.js index c837e9b..28b740c 100644 --- a/src/index.js +++ b/src/index.js @@ -121,13 +121,24 @@ class WireKVSDatabase extends EventEmitter { } async get(key) { - const response = await axios.get( - `${API_BASE_URL}/database/${this.id}/${key}`, - { - headers: { Authorization: this.accessKey }, + try { + const response = await axios.get( + `${API_BASE_URL}/database/${this.id}/${key}`, + { + headers: { Authorization: this.accessKey }, + } + ); + return response.data; + } catch (error) { + if ( + axios.isAxiosError(error) && + (error.response?.status === 404 || + error.response?.data?.message === "Key not found") + ) { + return; } - ); - return response.data; + throw error; + } } async json(key) {