mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37:45 +00:00
LibIMAP: Reject a promise if a response couldn't be parsed
Promises can take an Error type now for quite some time, so let's use it instead of returning an empty Optional type in the result field. :^) Ideally we should give a more detailed info of what failed to parse, but this will do for now.
This commit is contained in:
parent
55d730bd5c
commit
1f605407bd
1 changed files with 9 additions and 10 deletions
|
@ -193,7 +193,7 @@ NonnullRefPtr<Promise<Optional<T>>> cast_promise(NonnullRefPtr<Promise<Optional<
|
||||||
{
|
{
|
||||||
auto new_promise = promise_variant->map<Optional<T>>(
|
auto new_promise = promise_variant->map<Optional<T>>(
|
||||||
[](Optional<Response>& variant) {
|
[](Optional<Response>& variant) {
|
||||||
return variant.has_value() ? move(variant->get<T>()) : Optional<T>();
|
return move(variant->get<T>());
|
||||||
});
|
});
|
||||||
return new_promise;
|
return new_promise;
|
||||||
}
|
}
|
||||||
|
@ -250,8 +250,7 @@ ErrorOr<void> Client::handle_parsed_response(ParseStatus&& parse_status)
|
||||||
bool should_send_next = false;
|
bool should_send_next = false;
|
||||||
if (!parse_status.successful) {
|
if (!parse_status.successful) {
|
||||||
m_expecting_response = false;
|
m_expecting_response = false;
|
||||||
m_pending_promises.first()->resolve({});
|
m_pending_promises.take_first()->reject(Error::from_string_literal("Failed to parse message"));
|
||||||
m_pending_promises.remove(0);
|
|
||||||
}
|
}
|
||||||
if (parse_status.response.has_value()) {
|
if (parse_status.response.has_value()) {
|
||||||
m_expecting_response = false;
|
m_expecting_response = false;
|
||||||
|
@ -409,15 +408,15 @@ NonnullRefPtr<Promise<Optional<SolidResponse>>> Client::append(StringView mailbo
|
||||||
auto response_promise = Promise<Optional<Response>>::construct();
|
auto response_promise = Promise<Optional<Response>>::construct();
|
||||||
m_pending_promises.append(response_promise);
|
m_pending_promises.append(response_promise);
|
||||||
|
|
||||||
continue_req->on_resolution = [this, message2 { move(message) }](auto& data) -> ErrorOr<void> {
|
continue_req->on_resolution = [this, message2 { move(message) }](auto&) -> ErrorOr<void> {
|
||||||
if (!data.has_value()) {
|
TRY(send_raw(message2.data));
|
||||||
TRY(handle_parsed_response({ .successful = false, .response = {} }));
|
m_expecting_response = true;
|
||||||
} else {
|
|
||||||
TRY(send_raw(message2.data));
|
|
||||||
m_expecting_response = true;
|
|
||||||
}
|
|
||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
|
continue_req->on_rejection = [this](Error&) {
|
||||||
|
// NOTE: This never fails.
|
||||||
|
MUST(handle_parsed_response({ .successful = false, .response = {} }));
|
||||||
|
};
|
||||||
|
|
||||||
return cast_promise<SolidResponse>(response_promise);
|
return cast_promise<SolidResponse>(response_promise);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue