[tor-commits] [pluggable-transports/snowflake-webext] 01/15: refactor: simplify `getClientOffer`
gitolite role
git at cupani.torproject.org
Wed Nov 9 14:40:50 UTC 2022
This is an automated email from the git hooks/post-receive script.
cohosh pushed a commit to branch main
in repository pluggable-transports/snowflake-webext.
commit bac1ba798cca956cbcf913e277a00151d6fb315b
Author: WofWca <wofwca at protonmail.com>
AuthorDate: Fri Nov 4 12:19:14 2022 +0400
refactor: simplify `getClientOffer`
---
broker.js | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/broker.js b/broker.js
index 761efcf..f9be89f 100644
--- a/broker.js
+++ b/broker.js
@@ -51,22 +51,21 @@ class Broker {
if (xhr.DONE !== xhr.readyState) {
return;
}
- switch (xhr.status) {
- case Broker.CODE.OK: {
- const response = JSON.parse(xhr.responseText);
- if (response.Status == Broker.STATUS.MATCH) {
- return fulfill(response); // Should contain offer.
- } else if (response.Status == Broker.STATUS.TIMEOUT) {
- return reject(Broker.MESSAGE.TIMEOUT);
- } else {
- log('Broker ERROR: Unexpected ' + response.Status);
- return reject(Broker.MESSAGE.UNEXPECTED);
- }
+ if (xhr.status !== Broker.CODE.OK) {
+ log('Broker ERROR: Unexpected ' + xhr.status + ' - ' + xhr.statusText);
+ snowflake.ui.setStatus(' failure. Please refresh.');
+ reject(Broker.MESSAGE.UNEXPECTED);
+ return;
+ }
+ const response = JSON.parse(xhr.responseText);
+ switch (response.Status) {
+ case Broker.STATUS.MATCH: fulfill(response); return;
+ case Broker.STATUS.TIMEOUT: reject(Broker.MESSAGE.TIMEOUT); return;
+ default: {
+ log('Broker ERROR: Unexpected ' + response.Status);
+ reject(Broker.MESSAGE.UNEXPECTED);
+ return;
}
- default:
- log('Broker ERROR: Unexpected ' + xhr.status + ' - ' + xhr.statusText);
- snowflake.ui.setStatus(' failure. Please refresh.');
- return reject(Broker.MESSAGE.UNEXPECTED);
}
};
this._xhr = xhr; // Used by spec to fake async Broker interaction
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the tor-commits
mailing list