Skip to content

Commit

Permalink
fix: throw error on error response
Browse files Browse the repository at this point in the history
  • Loading branch information
friedger authored and hstove committed Jan 26, 2021
1 parent 952a60d commit 0a9a1ee
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/transactions/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,29 @@ export function hexToCV(hex: string) {
* @param {string} result - serialized hex clarity value
*/

export interface ReadOnlyFunctionResponse {
okay: boolean;
export interface ReadOnlyFunctionSuccessResponse {
okay: true;
result: string;
}

export interface ReadOnlyFunctionErrorResponse {
okay: false;
cause: string;
}

export type ReadOnlyFunctionResponse =
| ReadOnlyFunctionSuccessResponse
| ReadOnlyFunctionErrorResponse;

/**
* Converts the response of a read-only function call into its Clarity Value
* @param param
*/
export const parseReadOnlyResponse = ({ okay, result }: ReadOnlyFunctionResponse): ClarityValue => {
if (okay) {
return hexToCV(result);
export const parseReadOnlyResponse = (response: ReadOnlyFunctionResponse): ClarityValue => {
if (response.okay) {
return hexToCV(response.result);
} else {
return responseErrorCV(noneCV());
throw new Error(response.cause);
}
};

Expand Down

0 comments on commit 0a9a1ee

Please sign in to comment.