Vue Axios Uncaught (in promise) GET Request Error - javascript

axios.get('localhost:3000/api/event')
.then((response) => {
console.log(response);
});
The above code is being used in one of my Vue files and is retrieving data from a server I have set up and successfully tested endpoints with in Postman. The server is currently running, and I am trying to do a get request (from a separate file folder-my client) from the database. When I try this, I get "Uncaught (in promise) AxiosError \ code: ERR_BAD_REQUEST" in my console.
I have looked through other similar questions: vue axios Uncaught (in promise) Cancel , Vue axios error Uncaught (in promise) Error: Request failed with status code 415 , and others but found either an unsatisfactory answer or no answer at all.
My endpoint is correct, the server is running (I can query that same endpoint with Postman and get the JSONs I desire), and I believe my syntax is correct for the axios code. I would love some help with this please.

Related

Forbidden error HTTP Status 403 for Tableau getUnderlyingDataAsync API

I am using getUnderlyingDataAsync JS API to fetch data and to check the rowcount for a sheet for my local validation purpose and it works for creator role and not working for viewer or worker role. I got the below error. Is there any way I can bypass this error and why do we need to have this restriction for API calls?
ERROR Error: Uncaught (in promise): Error executing JS API command:
getUnderlyingDataAsync
Details:
api-get-worksheet-underlying-logical-table-data: {"code":0,"message":"PermissionDeniedException"}, status: 403, textStatus: error
at X (polyfills.0e0307f4410f68cf.js:1:16680)
at polyfills.0e0307f4410f68cf.js:1:15763
at v (main.bc6c811d2bb612a1.js:1:835786)
at Y (main.bc6c811d2bb612a1.js:1:835995)
.............

Uncaught (in promise) Type Error when trying to fetch for URL

I made a server using Node.js and used the Express framework. Once the server was running, I went to Google Chrome and when to inspect element and went to the console, and typed - fetch('http://localhost:7500'). I was expecting to get the CORS error(Which I wanted) but instead got this:
VM267:1 GET http://localhost:7200/ net::ERR_BLOCKED_BY_CLIENT
VM267:1 Uncaught (in promise) TypeError: Failed to fetch
at <anonymous>:1:1
Is there any way to resolve this error?

Unable to get data from API with axios: Uncaught (in promise) Error: Request failed with status code 404 [duplicate]

This question already has answers here:
Href without http(s) prefix
(4 answers)
Closed 1 year ago.
I'm trying to retrieve an object from an API with axios, but I get the following error:
Uncaught (in promise) Error: Request failed with status code 404
Pasting the same url in the browser gives me the correct view of the object, I don't know where the error is.
Code:
useEffect(() => {
axios
.get("www.themealdb.com/api/json/v1/1/random.php")
.then((res) => console.log(res));
});
I think you pass the invaild url to axios
//www.domain.com/page
the scheme may be not the same for the two requests
and the request headers are not the same
you should check the two requests.
most times, http and https do not response the same thing

Uncaught (in promise) SyntaxError: Unexpected end of input in React when fetching the API

Facing the error when I trying to use fetch(api) this in React.
fetch(url, {mode: "no-cors"})
.then(response => console.log(response.json()))
.catch(error => console.log('Error:', error));
The error message is:
PromiseĀ {: SyntaxError: Unexpected end of input
at http://localhost:3000/static/js/main.chunk.js:420:46} CalendarCommentary.js:22 Uncaught (in promise) SyntaxError: Unexpected
end of input
I'm using react and react-router-dom. I saw other answer is to add a header of server endpoint or something. But I cannot modify the server. Is there any other way to solve this?
You said:
{mode: "no-cors"}
This means "Do nothing that requires CORS. Do not report CORS related errors".
If you make a cross-origin request with this then the response will be blank. You cannot read the actual response without permission from CORS.
Since the response you are getting is blank you get to the end of it before any valid JSON is found (i.e. .json() expects to find JSON and unexpectedly gets to the end of the input before finding any).
Use:
{mode: "cors"}
But I cannot modify the server.
If the server doesn't grant permission via CORS, and you can't change that, then get the data from somewhere else (e.g. a proxy script on an origin you control).

Vue-JS/Axios Uncaught (in promise) Error: Network Error

I'm trying out VueJS and ended up having an issue with Axios and post request. I'm not sure is related to CORS (I had some at the beginning) or simply the way I handle the errors.
OPTIONS https://127.0.0.1:1880/api/v1/test-endpoint 0 ()
Uncaught (in promise) Error: Network Error at createError
(createError.js?16d0:16) at XMLHttpRequest.handleError
(xhr.js?ec6c:87)
Error Image
Any idea how I can fix it? I tried with other API online and it works perfectly (that's why I believe is some local setup/config I'm missing, especially with regards to CORS).
Thank you in advance

Categories

Resources