mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +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]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- @cosmjs/cosmwasm-stargate: Fix response error handling for smart queries.
|
||||||
|
|
||||||
## [0.26.3] - 2021-10-25
|
## [0.26.3] - 2021-10-25
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -120,10 +120,16 @@ export function setupWasmExtension(base: QueryClient): WasmExtension {
|
|||||||
const request = { address: address, queryData: toAscii(JSON.stringify(query)) };
|
const request = { address: address, queryData: toAscii(JSON.stringify(query)) };
|
||||||
const { data } = await queryService.SmartContractState(request);
|
const { data } = await queryService.SmartContractState(request);
|
||||||
// By convention, smart queries must return a valid JSON document (see https://github.com/CosmWasm/cosmwasm/issues/144)
|
// By convention, smart queries must return a valid JSON document (see https://github.com/CosmWasm/cosmwasm/issues/144)
|
||||||
|
let responseText: string;
|
||||||
try {
|
try {
|
||||||
return JSON.parse(fromUtf8(data));
|
responseText = fromUtf8(data);
|
||||||
} catch (error) {
|
} 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