Repository: angular
Issue: HttpTestingController can't mock HttpErrorResponse with successful status
Labels: type: bug/fix,help wanted,freq1: low,area: common/http,state: confirmed,P4

<!--
PLEASE HELP US PROCESS GITHUB ISSUES FASTER BY PROVIDING THE FOLLOWING INFORMATION.

ISSUES MISSING IMPORTANT INFORMATION MAY BE CLOSED WITHOUT INVESTIGATION.
-->

## I'm submitting a...
<!-- Check one of the following options with "x" -->
<pre><code>
[x] Regression (a behavior that used to work and stopped working in a new release)
</code></pre>

## Current behavior
<!-- Describe how the issue manifests. -->
I want to test HttpInterceptor when HttpErrorResponse has a successful (200) status. The situation became possible with the latest http client if response JSON is not valid [source](https://github.com/angular/angular/blob/317d40d879cc5eac1073a9182384423596fc098b/packages/common/http/src/xhr.ts#L199). But it's not possible to Mock HttpErrorResponse with a successful status [source](https://github.com/angular/angular/blob/cf0968f98e844043a0f6c2548201f3c0dfd329a7/packages/common/http/testing/src/request.ts#L83). TestRequest.error() is not allowing to mock such a behavior

NOTE:
I try to intercept requests with html content and perform a special action on them. With the previous implementation of http client such responses were handled as successful HttpResponses and should be handled in next callback, now they considered as HttpErrorResponses and should be handled in error handler. The current http client also ignores response Content-Type taking into account only request's Content-Type(Accept header): [https://github.com/angular/angular/blob/317d40d879cc5eac1073a9182384423596fc098b/packages/common/http/src/xhr.ts#L182](source) I would rather analyze both response and request Content-Type but that can be tricky and not as straightforward as extending/fixing TestRequest.

## Expected behavior
<!-- Describe what the desired behavior would be. -->
I should be able to mock HttpErrorResponse with successful status because it's possible to reproduce this case with the real http client

## Minimal reproduction of the problem with instructions
<!--
For bug reports please provide the *STEPS TO REPRODUCE* and if possible a *MINIMAL DEMO* of the problem via
https://stackblitz.com or similar (you can use this template as a starting point: https://stackblitz.com/fork/angular-gitter).
-->
```
describe('HttpTestingController test', () => {
    let httpMock: HttpTestingController;
    let http: HttpClient;
    beforeEach(() => {
        TestBed.configureTestingModule({
            imports: [HttpClientTestingModule]
        });
        httpMock = TestBed.get(HttpTestingController);
        http = TestBed.get(HttpClient);
    });

    it('should do request', () => {
        const uri = 'test\\api';
        http.get<{ data: string }>(uri).subscribe((e) => console.log(e));
        let response = httpMock.expectOne(uri);
        // shouldn't throw here:
        response.error(<any>{}, { status: 200, statusText: "OK", headers: new HttpHeaders({ 'Content-Type': 'text/html' }) });
    });
})
```
## What is the motivation / use case for changing the behavior?
<!-- Describe the motivation or the concrete use case. -->
I want to mock HttpErrorResponse with successful status to unit test custom HttpInterceptor

## Environment

<pre><code>
Angular version: 6.1.1
<!-- Check whether this is still an issue in the most recent Angular version -->

Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  <!-- run `node --version` -->
- Platform:  <!-- Mac, Linux, Windows -->

Others:
<!-- Anything else relevant?  Operating system version, IDE, package manager, HTTP server, ... -->
</code></pre>