diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp index bc53c3cd21..a8968f4543 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,18 @@ JS::NonnullGCPtr Response::network_error(JS::VM& vm) return response; } +// https://fetch.spec.whatwg.org/#appropriate-network-error +JS::NonnullGCPtr Response::appropriate_network_error(JS::VM& vm, FetchParams const& fetch_params) +{ + // 1. Assert: fetchParams is canceled. + VERIFY(fetch_params.is_canceled()); + + // 2. Return an aborted network error if fetchParams is aborted; otherwise return a network error. + return fetch_params.is_aborted() + ? aborted_network_error(vm) + : network_error(vm); +} + // https://fetch.spec.whatwg.org/#concept-aborted-network-error bool Response::is_aborted_network_error() const { diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h index 02edc09230..acfc2ad326 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h @@ -51,6 +51,7 @@ public: [[nodiscard]] static JS::NonnullGCPtr create(JS::VM&); [[nodiscard]] static JS::NonnullGCPtr aborted_network_error(JS::VM&); [[nodiscard]] static JS::NonnullGCPtr network_error(JS::VM&); + [[nodiscard]] static JS::NonnullGCPtr appropriate_network_error(JS::VM&, FetchParams const&); virtual ~Response() = default;