Skip to content

Commit c07d57c

Browse files
committed
fix(error-handling): Throw errors that do not have a response body
These errors occur for connection / request setup problems (i.e. if there is not internet connection)
1 parent 855278c commit c07d57c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/Instant2FA.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Instant2FA\Serializer\VerificationRequestSerializer;
1919
use Instant2FA\Serializer\VerificationResponseSerializer;
2020

21+
use Instant2FA\Error\Instant2FAException;
2122
use Instant2FA\Error\APIException;
2223
use Instant2FA\Error\MFANotEnabled;
2324
use Instant2FA\Error\VerificationFailedException;
@@ -80,6 +81,8 @@ public function create_settings($distinct_id) {
8081
$error_body = $response->getBody();
8182
$doc = $this->decoder->decode($error_body);
8283
throw new APIException($doc->errors);
84+
} else {
85+
throw new Instant2FAException($e->getMessage());
8386
}
8487
}
8588

@@ -110,6 +113,8 @@ public function create_verification($distinct_id) {
110113
$error_body = $response->getBody();
111114
$doc = $this->decoder->decode($error_body);
112115
throw new APIException($doc->errors);
116+
} else {
117+
throw new Instant2FAException($e->getMessage());
113118
}
114119
}
115120
$body = $response->getBody();
@@ -144,6 +149,8 @@ public function confirm_verification($distinct_id, $token) {
144149
$error_body = $response->getBody();
145150
$doc = $this->decoder->decode($error_body);
146151
throw new APIException($doc->errors);
152+
} else {
153+
throw new Instant2FAException($e->getMessage());
147154
}
148155
}
149156
$body = $response->getBody();

0 commit comments

Comments
 (0)