mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-02 23:53:35 +00:00
WakuStore.queryHistory
throws when encountering an error
Instead of returning a `null` value.
This commit is contained in:
parent
b422c9a10b
commit
319f44a0b1
@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Changed
|
||||
- **Breaking**: The `WakuMessage` APIs have been changed to move `contentTopic` out of the optional parameters.
|
||||
- **Breaking**: Move `contentTopics` out the `WakuStore.queryHistory`'s optional parameters.
|
||||
- **Breaking**: `WakuStore.queryHistory` throws when encountering an error instead of returning a `null` value.
|
||||
|
||||
### Removed
|
||||
- Examples (web-chat): Remove broken `/fleet` command.
|
||||
|
@ -62,13 +62,18 @@ async function retrieveStoreMessages(
|
||||
setArchivedMessages(messages);
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await waku.store.queryHistory([ChatContentTopic], {
|
||||
pageSize: 5,
|
||||
direction: Direction.FORWARD,
|
||||
callback,
|
||||
});
|
||||
|
||||
return res ? res.length : 0;
|
||||
return res.length;
|
||||
} catch {
|
||||
console.log('Failed to retrieve messages');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
|
@ -67,12 +67,12 @@ export class WakuStore {
|
||||
* @param options.decryptionKeys Keys that will be used to decrypt messages.
|
||||
* It can be Asymmetric Private Keys and Symmetric Keys in the same array, all keys will be tried with both
|
||||
* methods.
|
||||
* @throws If not able to reach the peer to query.
|
||||
* @throws If not able to reach the peer to query or error when processing the reply.
|
||||
*/
|
||||
async queryHistory(
|
||||
contentTopics: string[],
|
||||
options?: QueryOptions
|
||||
): Promise<WakuMessage[] | null> {
|
||||
): Promise<WakuMessage[]> {
|
||||
const opts = Object.assign(
|
||||
{
|
||||
pubsubTopic: this.pubsubTopic,
|
||||
@ -100,9 +100,7 @@ export class WakuStore {
|
||||
const messages: WakuMessage[] = [];
|
||||
let cursor = undefined;
|
||||
while (true) {
|
||||
try {
|
||||
const { stream } = await connection.newStream(StoreCodec);
|
||||
try {
|
||||
const queryOpts = Object.assign(opts, { cursor });
|
||||
const historyRpcQuery = HistoryRPC.createQuery(queryOpts);
|
||||
const res = await pipe(
|
||||
@ -112,21 +110,18 @@ export class WakuStore {
|
||||
lp.decode(),
|
||||
concat
|
||||
);
|
||||
try {
|
||||
const reply = HistoryRPC.decode(res.slice());
|
||||
|
||||
const response = reply.response;
|
||||
if (!response) {
|
||||
console.log('No response in HistoryRPC');
|
||||
return null;
|
||||
throw 'History response misses response field';
|
||||
}
|
||||
|
||||
if (
|
||||
response.error &&
|
||||
response.error === HistoryResponse_Error.ERROR_INVALID_CURSOR
|
||||
) {
|
||||
console.log('Error in response: INVALID CURSOR');
|
||||
return null;
|
||||
throw 'History response contains an Error: INVALID CURSOR';
|
||||
}
|
||||
|
||||
if (!response.messages || !response.messages.length) {
|
||||
@ -178,21 +173,6 @@ export class WakuStore {
|
||||
console.log('No cursor returned by peer.');
|
||||
return messages;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('Failed to decode store reply', err);
|
||||
return null;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('Failed to send waku store query', err);
|
||||
return null;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(
|
||||
'Failed to negotiate waku store protocol stream with peer',
|
||||
err
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user