Skip to content

Commit

Permalink
Add errorTitle prop for usePromise, useCachedPromise, and useFetch
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaslombart committed Jun 6, 2024
1 parent bb85878 commit 73d1a3a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/utils-reference/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ npm install --save @raycast/utils

## Changelog

### v1.16.0

- Add an `errorTitle` prop to `useFetch`, `useCachedPromise`, and `usePromise` to make it possible to customize the error displayed instead of a generic "Failed to fetch latest data".

### v1.15.0

- Add `useLocalStorage` hook.

### v1.14.0

- Add `useStreamJSON` hook.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@raycast/utils",
"version": "1.15.0",
"version": "1.16.0",
"description": "Set of utilities to streamline building Raycast extensions",
"author": "Raycast Technologies Ltd.",
"homepage": "https://developers.raycast.com/utils-reference",
Expand Down
2 changes: 2 additions & 0 deletions src/useFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export function useFetch<V = unknown, U = undefined, T extends unknown[] = unkno
onError,
onData,
onWillExecute,
errorTitle,
...fetchOptions
} = options || {};

Expand All @@ -136,6 +137,7 @@ export function useFetch<V = unknown, U = undefined, T extends unknown[] = unkno
onError,
onData,
onWillExecute,
errorTitle,
};

const parseResponseRef = useLatest(parseResponse || defaultParsing);
Expand Down
7 changes: 6 additions & 1 deletion src/usePromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export type PromiseOptions<T extends FunctionReturningPromise | FunctionReturnin
* wait util you have all the arguments ready to execute the function.
*/
execute?: boolean;
/**
* Custom error title for the generic failure toast.
* This will replace "Failed to fetch latest data".
*/
errorTitle?: string;
/**
* Called when an execution fails. By default it will log the error and show
* a generic failure toast.
Expand Down Expand Up @@ -183,7 +188,7 @@ export function usePromise<T extends FunctionReturningPromise | FunctionReturnin
} else {
if (environment.launchType !== LaunchType.Background) {
showFailureToast(error, {
title: "Failed to fetch latest data",
title: options?.errorTitle ?? "Failed to fetch latest data",
primaryAction: {
title: "Retry",
onAction(toast) {
Expand Down

0 comments on commit 73d1a3a

Please sign in to comment.