Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: registerErrorTransformer in composer #371

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2335219
fix: align AlgorandClientInterface with AlgorandClient (#355)
joe-p Jan 3, 2025
80709aa
remove implements AlgorandClientInterface for implementation
joe-p Jan 3, 2025
5271138
generate documentation
joe-p Jan 3, 2025
083e437
rename instance_of.ts to instance-of.ts
joe-p Jan 7, 2025
141494c
typedoc
joe-p Jan 7, 2025
b269dc0
feat: add registerErrorCallback function to composer
joe-p Jan 7, 2025
5401c13
adding registerErrorCallback to AlgorandClient
joe-p Jan 7, 2025
ae436ce
Merge branch 'fix/algorand_client_interface' into feat/composer_error…
joe-p Jan 7, 2025
b3ab709
register error map functions when an algorand client is used with a a…
joe-p Jan 7, 2025
c42bfd6
add test to ensure that AppClient registers the error map function
joe-p Jan 7, 2025
75fedd7
rm unused import, generate docs
joe-p Jan 7, 2025
63f0464
ErrorMapFunction -> ErrorTransformer
joe-p Jan 7, 2025
7cb6e8b
update docstrings
joe-p Jan 7, 2025
8881532
use object.assign to avoid any cast
joe-p Jan 7, 2025
cb38334
don't await sync iterable
joe-p Jan 7, 2025
37c68b7
check error message first before resorting to template literal
joe-p Jan 7, 2025
94abe7b
Check error instance before checking for match
joe-p Jan 7, 2025
d7d4462
typedoc
joe-p Jan 7, 2025
4eba5e2
fixture in describe block
joe-p Jan 7, 2025
842a0d6
use set instead of map
joe-p Jan 7, 2025
91903ea
ErrorTransformer always returns unknown
joe-p Jan 7, 2025
695d659
cleanup, renaming, comments, etc
joe-p Jan 7, 2025
c915e9c
don't use toString to check for app-specific error
joe-p Jan 8, 2025
f1fab2b
enforce TransformerError arg/return type as Error
joe-p Jan 8, 2025
3497fc6
pre-commit
joe-p Jan 8, 2025
9ae5932
const cb -> const transformer
joe-p Jan 8, 2025
eac0ebc
remove note about uknown type
joe-p Jan 8, 2025
d8aff7e
remove unnecessary Set.values()
joe-p Jan 8, 2025
e54d18e
typedoc
joe-p Jan 8, 2025
b75ff87
add BadTransformer Error
joe-p Jan 8, 2025
7aee94a
e -> originalError
joe-p Jan 8, 2025
838ecbf
typedoc
joe-p Jan 8, 2025
0ffca86
merge main
joe-p Jan 24, 2025
68674c0
ErrorTransformerError and minor touch-ups
joe-p Jan 24, 2025
b96eea6
Merge branch 'main' into feat/composer_error_callbacks
joe-p Jan 24, 2025
e6238f7
fix typos
joe-p Feb 3, 2025
6b1a8dc
rename InvalidErrorTransformerValue
joe-p Feb 3, 2025
bf9dc04
add docstring to InterfaceOf
joe-p Feb 3, 2025
0740e85
typedoc
joe-p Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/types/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,12 @@ export type Txn =
*/
export type ErrorTransformer = (error: Error) => Promise<Error>

class BadTransformer extends Error {
constructor(originalError: unknown) {
joe-p marked this conversation as resolved.
Show resolved Hide resolved
super(`An error transformer returned a non-error value. The original error before any transformation: ${originalError}`)
}
}

/** Parameters to create an `TransactionComposer`. */
export type TransactionComposerParams = {
/** The algod client to use to get suggestedParams and send the transaction group */
Expand Down Expand Up @@ -1324,10 +1330,13 @@ export class TransactionComposer {
this.algod,
)
} catch (e: unknown) {
// Transformers expect an Error, so don't transform the exception if it's not an Error
if (!(e instanceof Error)) throw e

let error = e
for (const transformer of this.errorTransformers) {
if (!(error instanceof Error)) {
joe-p marked this conversation as resolved.
Show resolved Hide resolved
break
throw new BadTransformer(e)
}
error = await transformer(error)
}
Expand Down