Skip to content

Commit

Permalink
improve http readCursor handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Dec 1, 2023
1 parent 5d6e2f3 commit 1d1d557
Show file tree
Hide file tree
Showing 2 changed files with 25 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": "substreams-sink",
"version": "0.13.3",
"version": "0.13.4",
"description": "Substreams Sink",
"type": "module",
"exports": "./dist/index.js",
Expand Down
26 changes: 24 additions & 2 deletions src/cursor/httpCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,29 @@ export async function readCursor(cursorPath: string, httpCursorAuth?: string) {
if (!response.ok) {
return "";
}
const text = await response.text();

const data: any = await response.json();
return data[0] && data[0].Value ? data[0].Value : "";
/**
* Consul KV
* https://developer.hashicorp.com/consul/api-docs/kv
*
* @example
* [{"Value":"n-5SB30M-16YouthlRFszqWwLpcyB1JpXQPsLRNL1..."}]
*/
try {
const data = JSON.parse(text) as { Value: string }[];
if ( data.length ) {
const value = data[0]?.Value;
if ( value ) return value;
}
/**
* Simple HTTP text response
*
* @example
* n-5SB30M-16YouthlRFszqWwLpcyB1JpXQPsLRNL1...
*/
} catch (error) {
if ( text ) return text;
}
return "";
}

0 comments on commit 1d1d557

Please sign in to comment.