andculturecode-javascript-core › Do
Utility class to be able to use strong typing in a catch handler. the Do.catch method takes a callback where the parameters are:
- result?: Result -- if it's an error from the server, will not be null
- error?: any -- if it's a Javascript error, will not be null
▪ TResourceType
▪ TReturnVal
- Do
+ new Do(workload: AsyncWorkload‹TReturnVal›): Do
Defined in src/utilities/do-try.ts:23
Parameters:
| Name | Type |
|---|---|
workload |
AsyncWorkload‹TReturnVal› |
Returns: Do
• promise: Promise‹TReturnVal›
Defined in src/utilities/do-try.ts:19
▸ catch(errorHandler: CatchResultHandler‹TResourceType›): Do‹TResourceType, TReturnVal›
Defined in src/utilities/do-try.ts:46
Handle errors from the workload. If errors are in the shape of a {ResultRecord}, you will get a typed {ResultRecord} as the first parameter. Otherwise, if it's an unknown error or Javascript error, you'll get an {any} as the second parameter.
Parameters:
| Name | Type | Description |
|---|---|---|
errorHandler |
CatchResultHandler‹TResourceType› | handle errors, either as a {ResultRecord} or {any} |
Returns: Do‹TResourceType, TReturnVal›
this
▸ finally(finallyHandler: FinallyHandler): Do‹TResourceType, TReturnVal›
Defined in src/utilities/do-try.ts:75
Run some handler when the function completes, whether the catch() was hit or not.
Parameters:
| Name | Type |
|---|---|
finallyHandler |
FinallyHandler |
Returns: Do‹TResourceType, TReturnVal›
this
▸ getAwaiter(): Promise‹TReturnVal›
Defined in src/utilities/do-try.ts:89
Awaits the internal promise being tracked by the Do instance, and returns the result. This way, you can await a Do.try chain, if you need to await for the result inside of another scope, such as tests.
Returns: Promise‹TReturnVal›
the result of the promise.
▸ configure(config: DoTryConfig): void
Defined in src/utilities/do-try.ts:65
Sets the global configuration object for class {Do}
Parameters:
| Name | Type | Description |
|---|---|---|
config |
DoTryConfig | the {DoTryConfig} object to set |
Returns: void
▸ try<TResourceType, TReturnVal>(workload: AsyncWorkload‹TReturnVal›): Do‹TResourceType, TReturnVal›
Defined in src/utilities/do-try.ts:100
Static factory method for Do class. Start a workload (sync or async) that you can then call .catch(catchHandler).finally(finallyHandler) on.
Type parameters:
▪ TResourceType
▪ TReturnVal
Parameters:
| Name | Type | Description |
|---|---|---|
workload |
AsyncWorkload‹TReturnVal› | a sync or async method to wrap |
Returns: Do‹TResourceType, TReturnVal›
a new instance of Do
Defined in src/utilities/do-try.ts:21
• defaultErrorHandler: undefined = undefined
Defined in src/utilities/do-try.ts:22