Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

javascript - 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) : ''))
    };
}
question from:https://stackoverflow.com/questions/65895209/how-to-fix-the-request-failed-with-status-code-500-when-reload-page-in-react

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...