From f168f9cd063c2597878fb11d7e3c75c8d389d574 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 16 Jan 2017 17:25:44 +0000 Subject: [PATCH 1/2] Fix vector-im/riot-web#2833 : Fail nicely when people try to register numeric user IDs --- src/Signup.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Signup.js b/src/Signup.js index f148ac2419..5d1c7062d5 100644 --- a/src/Signup.js +++ b/src/Signup.js @@ -203,7 +203,19 @@ class Register extends Signup { } else if (error.errcode == 'M_INVALID_USERNAME') { throw new Error("User names may only contain alphanumeric characters, underscores or dots!"); } else if (error.httpStatus >= 400 && error.httpStatus < 500) { - throw new Error(`Registration failed! (${error.httpStatus})`); + let msg = null; + if (error.message) { + msg = error.message; + } + else if (error.errcode) { + msg = error.errcode; + } + if (msg) { + throw new Error(`Registration failed! (${error.httpStatus}) - ${msg}`); + } + else { + throw new Error(`Registration failed! (${error.httpStatus}) - That's all we know.`); + } } else if (error.httpStatus >= 500 && error.httpStatus < 600) { throw new Error( `Server error during registration! (${error.httpStatus})` From 4f860b4c6dc42f7783c0e61611eb76462850ccd4 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 17 Jan 2017 10:50:44 +0000 Subject: [PATCH 2/2] Review comments: If-statement style --- src/Signup.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Signup.js b/src/Signup.js index 5d1c7062d5..d3643bd749 100644 --- a/src/Signup.js +++ b/src/Signup.js @@ -206,14 +206,12 @@ class Register extends Signup { let msg = null; if (error.message) { msg = error.message; - } - else if (error.errcode) { + } else if (error.errcode) { msg = error.errcode; } if (msg) { throw new Error(`Registration failed! (${error.httpStatus}) - ${msg}`); - } - else { + } else { throw new Error(`Registration failed! (${error.httpStatus}) - That's all we know.`); } } else if (error.httpStatus >= 500 && error.httpStatus < 600) {