Skip to content

Commit

Permalink
Account for fetch in promise (#223)
Browse files Browse the repository at this point in the history
* Account for fetch in promise

* Clenaup
  • Loading branch information
emilkowalski authored Nov 10, 2023
1 parent 48de91c commit 8472d54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,18 @@ class Observer {

let shouldDismiss = id !== undefined;

p.then((promiseData) => {
if (data.success !== undefined) {
p.then((response) => {
// TODO: Clean up TS here, response has incorrect type
// @ts-expect-error
if (response && typeof response.ok === 'boolean' && !response.ok) {
shouldDismiss = false;
const message = typeof data.success === 'function' ? data.success(promiseData) : data.success;
const message =
// @ts-expect-error
typeof data.error === 'function' ? data.error(`HTTP error! status: ${response.status}`) : data.error;
this.create({ id, type: 'error', message });
} else if (data.success !== undefined) {
shouldDismiss = false;
const message = typeof data.success === 'function' ? data.success(response) : data.success;
this.create({ id, type: 'success', message });
}
})
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/Types/Types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ toast.promise(promise, {
{
name: 'Custom',
snippet: `toast(<div>A custom toast with default styling</div>)`,
action: () => toast(<div>A custom toast with default styling</div>),
action: () => toast(<div>A custom toast with default styling</div>, { duration: 1000000 }),
},
];

1 comment on commit 8472d54

@vercel
Copy link

@vercel vercel bot commented on 8472d54 Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.