Commit 0856679f authored by yhirano's avatar yhirano Committed by Commit bot

[Fetch API] Streaming error should be reported as a TypeError

When the browser encounters an error while reading a response body, it should
error the body stream with a TypeError.

BUG=656601

Review-Url: https://codereview.chromium.org/2439673002
Cr-Commit-Position: refs/heads/master@{#427052}
parent f77c3ffe
......@@ -295,4 +295,12 @@ promise_test(t => {
});
}, 'Locked => text');
promise_test(t => {
return fetch('/fetch/resources/slow-failure.cgi').then(response => {
return response.text().then(unreached_fulfillment(t), e => {
assert_equals(e.name, 'TypeError');
});
});
}, 'streaming error');
done();
......@@ -96,4 +96,15 @@ promise_test(function(t) {
});
}, 'Cancelling stream should not affect cloned one.');
promise_test(t => {
let reader;
return fetch('/fetch/resources/slow-failure.cgi').then(res => {
reader = res.body.getReader();
return readableStreamToArray(res.body, reader);
}).then(unreached_fulfillment(t), e => {
reader.releaseLock();
assert_equals(e.name, 'TypeError');
});
}, 'Streaming error should be reported as a TypeError.');
done();
......@@ -6,6 +6,7 @@
#include "bindings/core/v8/ScriptState.h"
#include "bindings/core/v8/V8HiddenValue.h"
#include "bindings/core/v8/V8ThrowException.h"
#include "core/dom/DOMArrayBuffer.h"
#include "core/dom/DOMTypedArray.h"
#include "core/dom/ExceptionCode.h"
......@@ -285,7 +286,11 @@ void BodyStreamBuffer::close() {
}
void BodyStreamBuffer::error() {
controller()->error(DOMException::create(NetworkError, "network error"));
{
ScriptState::Scope scope(m_scriptState.get());
controller()->error(V8ThrowException::createTypeError(
m_scriptState->isolate(), "network error"));
}
cancelConsumer();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment