[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Result](https://evolu.dev/docs/api-reference/common/Result) › tryAsync

```ts
function tryAsync<T, E>(
  lazyPromise: Lazy<Promise<T>>,
  mapError: (error: unknown) => E,
): Promise<Result<T, E>>;
```

Defined in: [packages/common/src/Result.ts:440](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Result.ts#L440)

Wraps an async function that may throw, returning a [Result](https://evolu.dev/docs/api-reference/common/Result/type-aliases/Result).

Use this when the rejection should become a typed, recoverable error for the
caller. Do not use it for failures that should terminate the current flow and
propagate to a global handler.

### Example

```ts
const fetchJson = (url: string): Promise<Result<unknown, FetchError>> =>
  tryAsync(
    async () => {
      const response = await fetch(url);
      if (!response.ok) throw new Error(`Status ${response.status}`);
      return response.json();
    },
    (error) => ({ type: "FetchError", message: String(error) }),
  );
```