1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:17:34 +00:00

LibWeb: Require error message for Response::network_error()

There will be a lot of different cases where we'll return an error
response, and having a customized Promise rejection message seems quite
useful.

Note that this has to be distinct from the existing 'status message',
which is required to be empty in those cases.
This commit is contained in:
Linus Groh 2022-10-23 19:10:17 +02:00
parent d8ebdef010
commit 32e0f0aec8
3 changed files with 12 additions and 6 deletions

View file

@ -50,7 +50,7 @@ public:
[[nodiscard]] static JS::NonnullGCPtr<Response> create(JS::VM&);
[[nodiscard]] static JS::NonnullGCPtr<Response> aborted_network_error(JS::VM&);
[[nodiscard]] static JS::NonnullGCPtr<Response> network_error(JS::VM&);
[[nodiscard]] static JS::NonnullGCPtr<Response> network_error(JS::VM&, String message);
[[nodiscard]] static JS::NonnullGCPtr<Response> appropriate_network_error(JS::VM&, FetchParams const&);
virtual ~Response() = default;
@ -107,6 +107,9 @@ public:
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> clone(JS::VM&) const;
// Non-standard
Optional<String> const& network_error_message() const { return m_network_error_message; }
protected:
explicit Response(JS::NonnullGCPtr<HeaderList>);
@ -171,6 +174,9 @@ private:
// https://fetch.spec.whatwg.org/#response-has-cross-origin-redirects
// A response has an associated has-cross-origin-redirects (a boolean), which is initially false.
bool m_has_cross_origin_redirects { false };
// Non-standard
Optional<String> m_network_error_message;
};
// https://fetch.spec.whatwg.org/#concept-filtered-response
@ -291,5 +297,4 @@ private:
JS::NonnullGCPtr<HeaderList> m_header_list;
Optional<Body> m_body;
};
}