Skip to content

Commit b5f797c

Browse files
authored
fix: getMessages now fails silently (#140)
* fix: getMessages now fails silently A query with no results is an acceptable response. If any.GetMessages has no match it still returns an empty array. It is up to the user to handle rejection (.... or not).
1 parent f83008a commit b5f797c

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

src/messages/any/getMessage.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ export async function GetMessage<T = BaseMessage>({
3636
APIServer,
3737
};
3838

39-
try {
40-
const response = await GetMessages(params);
41-
return response.messages[0] as unknown as T;
42-
} catch {
39+
const response = await GetMessages(params);
40+
if (response.messages.length === 0) {
4341
throw new Error(`No messages found for: ${hash}`);
4442
}
43+
return response.messages[0] as unknown as T;
4544
}

src/messages/any/getMessages.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,5 @@ export async function GetMessages({
8686
socketPath: getSocketPath(),
8787
});
8888

89-
if (response.data.messages.length > 0) return response.data;
90-
throw new Error(`No messages found`);
89+
return response.data;
9190
}

tests/messages/any/get.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ describe("Test features from GetMessage", () => {
156156
});
157157
});
158158

159-
it("If a specific message does not exist, it should failed", async () => {
160-
await expect(
161-
any.GetMessages({
162-
hashes: ["w87e1e2ee2cbe88fa2923042b84b2f9c694w10005ca7dd40193838bf9bad18e12cw"],
163-
}),
164-
).rejects.toThrow("No messages found");
159+
it("If a specific message does not exist, it should return an empty array", async () => {
160+
const msg = await any.GetMessages({
161+
hashes: ["w87e1e2ee2cbe88fa2923042b84b2f9c694w10005ca7dd40193838bf9bad18e12cw"],
162+
});
163+
164+
expect(msg.messages.length).toStrictEqual(0);
165165
});
166166

167167
it("try by all message type", async () => {

0 commit comments

Comments
 (0)