Merge pull request #160 from CosmWasm/show-txid-in-error

Show transaction ID when error code is set
This commit is contained in:
Simon Warta 2020-04-02 20:07:32 +02:00 committed by GitHub
commit 66720c0ec5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -300,14 +300,16 @@ export class CosmWasmClient {
public async postTx(tx: StdTx): Promise<PostTxResult> {
const result = await this.restClient.postTx(tx);
if (result.code) {
throw new Error(`Error when posting tx. Code: ${result.code}; Raw log: ${result.raw_log}`);
}
if (!result.txhash.match(/^([0-9A-F][0-9A-F])+$/)) {
throw new Error("Received ill-formatted txhash. Must be non-empty upper-case hex");
}
if (result.code) {
throw new Error(
`Error when posting tx ${result.txhash}. Code: ${result.code}; Raw log: ${result.raw_log}`,
);
}
return {
logs: result.logs ? parseLogs(result.logs) : [],
rawLog: result.raw_log || "",