question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way to set global options on HttpClient ( { observe: 'response' } )

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/....

HttpClient / HttpInterceptor

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

Description

A clear and concise description of the problem...

There doesn’t seem to be a way to set global options for an HttpClient. The only close option I see is configuring an HttpInterceptor and set the options within each request.

const req = _request.clone(<Update Object>);

It doesn’t look like the update object is aware of the HttpClient options such as { observe: 'response }

clone(update: {
        headers?: HttpHeaders;
        reportProgress?: boolean;
        params?: HttpParams;
        responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
        withCredentials?: boolean;
        body?: T | null;
        method?: string;
        url?: string;
        setHeaders?: {
            [name: string]: string | string[];
        };
        setParams?: {
            [param: string]: string;
        };
    }): HttpRequest<T>;

πŸ”¬ Minimal Reproduction

https://stackblitz.com/...

πŸ”₯ Exception or Error





🌍 Your Environment

Angular Version:





Anything else relevant?

I’m not clear if there is some other way to handle this as my use case is to simply get the Http Response Code from the response. Of course, I can configure the { observe: β€˜response’ } on every call, but that is error prone (someone would eventually not add it).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JoostKcommented, Apr 5, 2019

One reason I could think of for not being able to set the response format globally is that it would break libraries that also use HttpClient themselves. Furthermore, API consumers would not be able to be type-checked properly, this is also why an interceptor can’t change the response format right now.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 15, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set the { observe: 'response' } option globally in ...
So, is there, if any, method to set the { observe: 'response' } option globally, e.g. via the HttpInterceptor ? clone(update: { headers?:...
Read more >
Communicating with backend services using HTTP - Angular
The observe option specifies how much of the response to return ... for example, the service set the default headers using the headers...
Read more >
The new Angular HttpClient API - Medium
The HttpClient API was introduced in the version 4.3.0. It is an evolution of the existing HTTP API and has it's own package...
Read more >
Angular HttpClient post - ConcretePage.com
The HttpClient.post method can use observe property in http options to define whether we want complete response or body only or events only....
Read more >
Angular Basics: How To Use HttpClient in Angular - Telerik
options – It is used to configure the HTTP request. It is optional and of type object , and its default value is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found