mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 13:47:12 +00:00
Fix response error handling for smart queries
This commit is contained in:
parent
a4d4d4382f
commit
e754fad581
@ -6,6 +6,10 @@ and this project adheres to
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- @cosmjs/cosmwasm-stargate: Fix response error handling for smart queries.
|
||||
|
||||
## [0.26.3] - 2021-10-25
|
||||
|
||||
### Added
|
||||
|
@ -120,10 +120,16 @@ export function setupWasmExtension(base: QueryClient): WasmExtension {
|
||||
const request = { address: address, queryData: toAscii(JSON.stringify(query)) };
|
||||
const { data } = await queryService.SmartContractState(request);
|
||||
// By convention, smart queries must return a valid JSON document (see https://github.com/CosmWasm/cosmwasm/issues/144)
|
||||
let responseText: string;
|
||||
try {
|
||||
return JSON.parse(fromUtf8(data));
|
||||
responseText = fromUtf8(data);
|
||||
} catch (error) {
|
||||
throw new Error("Contract did not return valid JSON data");
|
||||
throw new Error(`Could not UTF-8 decode smart query response from contract: ${error}`);
|
||||
}
|
||||
try {
|
||||
return JSON.parse(responseText);
|
||||
} catch (error) {
|
||||
throw new Error(`Could not JSON parse smart query response from contract: ${error}`);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user