Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
request failed with status code 400

I am running server in nodejs, while executing the code of server i am getting an error as "(node:7692) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Request failed with status code 400 (node:7692) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code".

this is my serverrender.js code

import axios from 'axios';
import config from './config';

axios.get('${config.serverUrl/api/contests')
.then(resp=>{
    console.log(resp.data);
});

this is my srver.js code

    import config from './config';
    import apiRouter from './api';
    import express from 'express';
    import path from 'path';
    import sassMiddleware from 'node-sass-middleware';

    import './serverRender';
    const server=express();
    server.set('view engine','ejs');

    server.use(sassMiddleware({
        src:path.join(__dirname,'sass'),
        dest:path.join(__dirname,'public')
    }));

    server.get('/',(req,res)=>{

        res.render('index',{
            content:"... "
        });


});
server.use(express.static('public'));

server.use('/api',apiRouter);

server.listen(config.port, config.host, () =>{
    console.info('express listening on port ',config.port);
});
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You should add a catch to the get call:

import axios from 'axios';
import config from './config';

axios.get('${config.serverUrl/api/contests')
  .then(resp=>{
    console.log(resp.data);
  })  
  .catch(error=>{

  });
over 4 years ago · Santiago Trujillo Denunciar

0

You need to enclose the opening parentheses of the config variable.

import axios from 'axios';
import config from './config';

axios.get(`${config.serverUrl}/api/contests`)
  .then(resp=>{
    console.log(resp.data);
  })  
  .catch(error=>{

  });
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda