@@ -25,32 +25,26 @@ import java.io.IOException
2525import java.net.UnknownHostException
2626import javax.net.ssl.HttpsURLConnection
2727
28- fun Throwable.is401 () =
29- this is Failure .ServerError &&
30- httpCode == HttpsURLConnection .HTTP_UNAUTHORIZED && /* 401 */
31- error.code == MatrixError .M_UNAUTHORIZED
32-
33- fun Throwable.is404 () =
34- this is Failure .ServerError &&
35- httpCode == HttpsURLConnection .HTTP_NOT_FOUND && /* 404 */
36- error.code == MatrixError .M_NOT_FOUND
37-
38- fun Throwable.isTokenError () =
39- this is Failure .ServerError &&
40- (error.code == MatrixError .M_UNKNOWN_TOKEN ||
41- error.code == MatrixError .M_MISSING_TOKEN ||
42- error.code == MatrixError .ORG_MATRIX_EXPIRED_ACCOUNT )
43-
44- fun Throwable.isLimitExceededError () =
45- this is Failure .ServerError &&
46- httpCode == 429 &&
47- error.code == MatrixError .M_LIMIT_EXCEEDED
48-
49- fun Throwable.shouldBeRetried (): Boolean {
50- return this is Failure .NetworkConnection ||
51- this is IOException ||
52- this .isLimitExceededError()
53- }
28+ fun Throwable.is401 () = this is Failure .ServerError &&
29+ httpCode == HttpsURLConnection .HTTP_UNAUTHORIZED && /* 401 */
30+ error.code == MatrixError .M_UNAUTHORIZED
31+
32+ fun Throwable.is404 () = this is Failure .ServerError &&
33+ httpCode == HttpsURLConnection .HTTP_NOT_FOUND && /* 404 */
34+ error.code == MatrixError .M_NOT_FOUND
35+
36+ fun Throwable.isTokenError () = this is Failure .ServerError &&
37+ (error.code == MatrixError .M_UNKNOWN_TOKEN ||
38+ error.code == MatrixError .M_MISSING_TOKEN ||
39+ error.code == MatrixError .ORG_MATRIX_EXPIRED_ACCOUNT )
40+
41+ fun Throwable.isLimitExceededError () = this is Failure .ServerError &&
42+ httpCode == 429 &&
43+ error.code == MatrixError .M_LIMIT_EXCEEDED
44+
45+ fun Throwable.shouldBeRetried () = this is Failure .NetworkConnection ||
46+ this is IOException ||
47+ isLimitExceededError()
5448
5549/* *
5650 * Get the retry delay in case of rate limit exceeded error, adding 100 ms, of defaultValue otherwise
@@ -64,46 +58,33 @@ fun Throwable.getRetryDelay(defaultValue: Long): Long {
6458 ? : defaultValue
6559}
6660
67- fun Throwable.isUsernameInUse (): Boolean {
68- return this is Failure .ServerError && error.code == MatrixError .M_USER_IN_USE
69- }
61+ fun Throwable.isUsernameInUse () = this is Failure .ServerError &&
62+ error.code == MatrixError .M_USER_IN_USE
7063
71- fun Throwable.isInvalidUsername (): Boolean {
72- return this is Failure .ServerError &&
73- error.code == MatrixError .M_INVALID_USERNAME
74- }
64+ fun Throwable.isInvalidUsername () = this is Failure .ServerError &&
65+ error.code == MatrixError .M_INVALID_USERNAME
7566
76- fun Throwable.isInvalidPassword (): Boolean {
77- return this is Failure .ServerError &&
78- error.code == MatrixError .M_FORBIDDEN &&
79- error.message == " Invalid password"
80- }
67+ fun Throwable.isInvalidPassword () = this is Failure .ServerError &&
68+ error.code == MatrixError .M_FORBIDDEN &&
69+ error.message == " Invalid password"
8170
82- fun Throwable.isRegistrationDisabled (): Boolean {
83- return this is Failure .ServerError && error.code == MatrixError .M_FORBIDDEN &&
84- httpCode == HttpsURLConnection .HTTP_FORBIDDEN
85- }
71+ fun Throwable.isRegistrationDisabled () = this is Failure .ServerError &&
72+ error.code == MatrixError .M_FORBIDDEN &&
73+ httpCode == HttpsURLConnection .HTTP_FORBIDDEN
8674
87- fun Throwable.isWeakPassword (): Boolean {
88- return this is Failure .ServerError && error.code == MatrixError .M_WEAK_PASSWORD
89- }
75+ fun Throwable.isWeakPassword () = this is Failure .ServerError &&
76+ error.code == MatrixError .M_WEAK_PASSWORD
9077
91- fun Throwable.isLoginEmailUnknown (): Boolean {
92- return this is Failure .ServerError &&
93- error.code == MatrixError .M_FORBIDDEN &&
94- error.message.isEmpty()
95- }
78+ fun Throwable.isLoginEmailUnknown () = this is Failure .ServerError &&
79+ error.code == MatrixError .M_FORBIDDEN &&
80+ error.message.isEmpty()
9681
97- fun Throwable.isInvalidUIAAuth (): Boolean {
98- return this is Failure .ServerError &&
99- error.code == MatrixError .M_FORBIDDEN &&
100- error.flows != null
101- }
82+ fun Throwable.isInvalidUIAAuth () = this is Failure .ServerError &&
83+ error.code == MatrixError .M_FORBIDDEN &&
84+ error.flows != null
10285
103- fun Throwable.isHomeserverUnavailable (): Boolean {
104- return this is Failure .NetworkConnection &&
105- this .ioException is UnknownHostException
106- }
86+ fun Throwable.isHomeserverUnavailable () = this is Failure .NetworkConnection &&
87+ this .ioException is UnknownHostException
10788
10889/* *
10990 * Try to convert to a RegistrationFlowResponse. Return null in the cases it's not possible
@@ -135,13 +116,11 @@ fun Throwable.toRegistrationFlowResponse(): RegistrationFlowResponse? {
135116 }
136117}
137118
138- fun Throwable.isRegistrationAvailabilityError (): Boolean {
139- return this is Failure .ServerError &&
140- httpCode == HttpsURLConnection .HTTP_BAD_REQUEST && /* 400 */
141- (error.code == MatrixError .M_USER_IN_USE ||
142- error.code == MatrixError .M_INVALID_USERNAME ||
143- error.code == MatrixError .M_EXCLUSIVE )
144- }
119+ fun Throwable.isRegistrationAvailabilityError () = this is Failure .ServerError &&
120+ httpCode == HttpsURLConnection .HTTP_BAD_REQUEST && /* 400 */
121+ (error.code == MatrixError .M_USER_IN_USE ||
122+ error.code == MatrixError .M_INVALID_USERNAME ||
123+ error.code == MatrixError .M_EXCLUSIVE )
145124
146125/* *
147126 * Try to convert to a ScanFailure. Return null in the cases it's not possible
0 commit comments