ABC
ABC

Reputation: 832

How to fix the Request failed with status code 500 when reload page in react

The problem here is when every time I reload the page I'm getting this error. which is the Uncaught (in promise) Error: Request failed with status code 500.

here's my code in list.tsx

const [state, setState] = useState([]);

    const { getRoom } = useRoom();

    const fetchData = async () => {
        return getRoom().then((res) => setState(res['data'].data));
    }
    
    useEffect(() => {
        (async function fetchData() {
            await fetchData();
        })();
    })

code for room.tsx

function useRoom() {

    const creds = useCredentials();

    Axios.defaults.baseURL = serverConfig[creds.server].api;

    return {
        getRoom: (params?: object) => Axios.get(`${API_URL}/room` + (params ? getQueryParams(params) : ''))
    };
}

Upvotes: 0

Views: 6136

Answers (1)

Dennis Hackethal
Dennis Hackethal

Reputation: 14275

500 is an error code servers produce. That's not necessarily something you can fix on the client. You'll need to understand which request the server returns a 500 to and why. Then maybe you can change something on the client (e.g. a malformed request). Or maybe you'll need to change something on the server.

Either way, looking only at the client-side JS code won't help you fix this.

Upvotes: 1

Related Questions