Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!