Error: read ECONNRESET Axios in backend Node js

2k views Asked by At

I am using axios in the backend nodejs and wanted to fetch the data of the movie database API. when is send request from frontend to my nodejs API it gives Error: read ECONNRESET error. But sometimes it works properly. here is my API route :-

app.get("/api/v1/movie/details/:movieId",(req,res) => { const id = req.params.movieId;
  let results = {};
  axios
    .get(
      `/movie/${id}?api_key=${process.env.API_KEY}&language=en-US&append_to_response=videos,credits`
    )
    .then((response) => {
      results = { ...response.data };
      return res.status(200).json(results);
    })
    .catch((e) => {
      console.log(e);
      return res.status(500).json(e.message);
    });});

And here is the error I am getting in console

Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:205:27) {
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read',
  config: {
    url: '/movie/556984?api_key=API_KEY&language=en-US&append_to_response=videos,credits',
    method: 'get',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.20.0'
    },
    baseURL: 'https://api.themoviedb.org/3',
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    data: undefined
  },

I don't understand how sometimes it working but sometimes its showing this error. But whenever I send request to directly to the movie database API from the browser (not sending to my own API) i got response everytime... please help me !!!

0

There are 0 answers