Zhichang Yu 185c6a0c71
Unified API response json schema (#3170)
### What problem does this PR solve?

Unified API response json schema

### Type of change

- [x] Refactoring
2024-11-05 11:02:31 +08:00

19 lines
447 B
TypeScript

import axios from 'axios';
import { useCallback, useEffect, useState } from 'react';
export const useCatchDocumentError = (url: string) => {
const [error, setError] = useState<string>('');
const fetchDocument = useCallback(async () => {
const { data } = await axios.get(url);
if (data.code !== 0) {
setError(data?.message);
}
}, [url]);
useEffect(() => {
fetchDocument();
}, [fetchDocument]);
return error;
};