<p dir="auto"><strong>I'm submitting a ...</strong>  (check one with "x")</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[x] bug report =&gt; search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question"><pre class="notranslate"><code class="notranslate">[x] bug report =&gt; search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
</code></pre></div>
<p dir="auto"><strong>Current behavior</strong><br>
I'm testing a service that we're connecting with HTTP. I wanted to make sure that not-ok responses (non 200 status), are dealt with correctly.<br>
So I've setup a test with a MockBackend. In this tests, I've setup the response to respond with an error Response:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const response = new Response(new ResponseOptions({
  url: 'url',
  status: 500,
  body: {
   error: 'Shit hit the fan'
  }
}));

backend.connections.subscribe((connection: MockConnection) =&gt; {
  connection.mockRespond(response);
});"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">response</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Response</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-smi">ResponseOptions</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
  <span class="pl-c1">url</span>: <span class="pl-s">'url'</span><span class="pl-kos">,</span>
  <span class="pl-c1">status</span>: <span class="pl-c1">500</span><span class="pl-kos">,</span>
  <span class="pl-c1">body</span>: <span class="pl-kos">{</span>
   <span class="pl-c1">error</span>: <span class="pl-s">'Shit hit the fan'</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-s1">backend</span><span class="pl-kos">.</span><span class="pl-c1">connections</span><span class="pl-kos">.</span><span class="pl-en">subscribe</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-s1">connection</span>: <span class="pl-smi">MockConnection</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-s1">connection</span><span class="pl-kos">.</span><span class="pl-en">mockRespond</span><span class="pl-kos">(</span><span class="pl-s1">response</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Unfortunately, the MockBackend seems to behave different from the actual Http implementation. The actual Http implementation will throw an error when receiving an non-200 response while the MockBackend simply passes the Response along.<br>
This is demonstrated by:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="http.get('url').subscribe((response) =&gt; {
  console.log('incorrectly passed the response in a subscribe');
}, (error) =&gt; {
  console.log('correctly subscribed to', error);
});"><pre class="notranslate"><span class="pl-s1">http</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">'url'</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">subscribe</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-s1">response</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'incorrectly passed the response in a subscribe'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">error</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'correctly subscribed to'</span><span class="pl-kos">,</span> <span class="pl-s1">error</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">This always logs "incorrectly passed the response in a then".</p>
<p dir="auto">I could change the configuration of the backend to respond with an error <code class="notranslate">connection.mockError(response);</code> but this function expects an <code class="notranslate">Error</code> rather than a <code class="notranslate">Response</code></p>
<p dir="auto"><strong>Expected behaviour</strong><br>
I would expect the response to be passed to the error callback.</p>
<p dir="auto">Note that I'm using angular 4.1.0 with typescript 2.2.0.</p>
<p dir="auto"><strong>I'm submitting a ...</strong>  (check one with "x")</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[ x] bug report =&gt; search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question"><pre class="notranslate"><code class="notranslate">[ x] bug report =&gt; search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
</code></pre></div>
<p dir="auto"><strong>Current behavior</strong><br>
Test Repo - <a href="https://github.com/mildfuzz/angular-mockError">https://github.com/mildfuzz/angular-mockError</a></p>
<p dir="auto">I am unable to test predicted HTTP error responses. Mockbackend can either send a response with an error code (which my app treats as a successful response in the test environment, but as an error in real world)</p>
<p dir="auto">I am unable to send status codes with an error response in my tests, so I can not test any error handling my application might implements.</p>
<p dir="auto"><strong>Expected behavior</strong><br>
at least one of the defined test cases passes</p>
<p dir="auto"><strong>Minimal reproduction of the problem with instructions</strong><br>
Test Repo - <a href="https://github.com/mildfuzz/angular-mockError">https://github.com/mildfuzz/angular-mockError</a></p>
<p dir="auto">this is a re-opening of issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="139123794" data-permission-text="Title is private" data-url="https://github.com/angular/angular/issues/7471" data-hovercard-type="issue" data-hovercard-url="/angular/angular/issues/7471/hovercard" href="https://github.com/angular/angular/issues/7471">#7471</a>, which was closed due to lack of repro steps.</p>
<p dir="auto"><strong>What is the motivation / use case for changing the behavior?</strong><br>
To be able to test all responses</p>
<p dir="auto"><strong>Please tell us about your environment:</strong><br>
OsX</p>
<ul dir="auto">
<li>
<p dir="auto"><strong>Angular version:</strong> 2.0.X<br>
Angular 2.1.0</p>
</li>
<li>
<p dir="auto"><strong>Browser:</strong> [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]<br>
Chrome 54</p>
</li>
<li>
<p dir="auto"><strong>Language:</strong> TypeScript 2.0.3</p>
</li>
<li>
<p dir="auto"><strong>Node (for AoT issues):</strong> <code class="notranslate">node --version</code> =   6.9.1</p>
</li>
</ul>