axios: AxiosError {message: 'Request failed with status code 500', name: 'AxiosError', code: 'ERR_BAD_RESPONSE', config: {…}, request: XMLHttpRequest, …

Describe the issue

code : “ERR_BAD_RESPONSE” config : {transitional: {…}, adapter: ‘xhr’, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …} message : “Request failed with status code 500” name : “AxiosError” request : XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …} response : {data: ‘Internal error’, status: 500, statusText: ‘Internal Server Error’, headers: AxiosHeaders, config: {…}, …} stack : “AxiosError: Request failed with status code 500\n at settle (webpack-internal:///(app-pages-browser)/./node_modules/axios/lib/core/settle.js:24:12)\n at XMLHttpRequest.onloadend (webpack-internal:///(app-pages-browser)/./node_modules/axios/lib/adapters/xhr.js:121:66)” [[Prototype]] : Error

Example Code

const isLoading = form.formState.isSubmitting;
const onSubmit = async (values: z.infer<typeof formSchema>) => {
    try {
        const userMessage: ChatCompletionRequestMessage = {
            role: "user",
            content: values.prompt,
        };
        const newMessages = [...messages, userMessage];
        const response = await axios.post("/api/conversation", {
            messages: newMessages,
        });
        setMessages((current) => [...current, userMessage, response.data]);
        form.reset();
    } catch (error: any) {
        console.log(error)
    } finally {
        router.refresh();
    }

Expected behavior

using openai api

Axios Version

No response

Adapter Version

No response

Browser

chrome

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

No response

Additional context/Screenshots

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15

Most upvoted comments

Just use useEffect