Skip to content

Commit

Permalink
Merge pull request #213 from Team-Crops/fix/195-verbose-toastify
Browse files Browse the repository at this point in the history
`Toastify` 조용히 시키기
  • Loading branch information
jaewoongs authored Jun 24, 2024
2 parents 2c8c7d9 + fc8ebfb commit 6cd3f46
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utilities/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { toast } from 'react-toastify';
import returnFetch from 'return-fetch';

import { ApiError } from '#/types';
import { getTokens } from '#/utilities/session';

export const fitFetch = returnFetch({
Expand All @@ -22,10 +23,15 @@ export const fitFetch = returnFetch({
});

export const fitFetcher = async <T>(...args: Parameters<typeof fitFetch>) => {
const toastExclusionCodes = [
ApiError.INVALID_ACCESS_TOKEN_CODE,
ApiError.MATCHING_NOT_FOUND_CODE,
];

const res = await fitFetch(...args);
try {
const json = await res.json();
if (!res.ok && json?.message) {
if (!res.ok && json.message && !toastExclusionCodes.includes(json.code)) {
toast.error(json.message);
}
return res.ok ? (json as T) : Promise.reject(json as Error);
Expand Down

0 comments on commit 6cd3f46

Please sign in to comment.