Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda