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

119
Vistas
Adding property to URL config

So I want to modify a request header via my interceptor, however when I set the content type of a request the request function stops without any error.

The function stops at the line config.headers['Content-Type'] = 'application/json';

I'm thinking it's because the property 'Content-Type' doesn't exist on the object header but i'm pretty sure it's possible to add properties to an object like this in js.

const requestLogin = async (loginDTO) => {
        let requestOptions = {
            method: 'POST',
            body: JSON.stringify(loginDTO)
        };
        return await fetch(`${baseURL}/Account/Login`, requestOptions);
    }

request: function (url, config) {
            // Modify the url or config here
            if (!config) return;
            config.headers['Content-Type'] = 'application/json';
            return [url, config];
        },
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can set config.headers['Content-Type'] if config.headers is already an object. If it is not then you get a TypeError.

Try to write a more strict guard:

if (!config || !config.headers || typeof config.headers !== 'object') return;
config.headers['Content-Type'] = 'application/json';
return [url, config];
about 4 years ago · Juan Pablo Isaza 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