PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
← All changes | app/Features/Onboarding/Services/CreateAccountService.php +7 -16 2.0.2 → 2.1.1 View file →
@@ -1,11 +1,12 @@
1 1 <?php
2 2
3 3 namespace Metricool\Features\Onboarding\Services;
4 4
5 -use GuzzleHttp\Exception\GuzzleException;
5 +use Metricool\Exceptions\RestDataException;
6 6 use Metricool\Features\Onboarding\Exceptions\CreateAccountException;
7 7 use Metricool\Features\Onboarding\OnboardingService;
8 +use Metricool\Http\Metricool\Exceptions\ApiException;
8 9 use Metricool\Http\Metricool\MetricoolApi;
9 10 use Metricool\Http\RSPAL\RspalApiClient;
10 11 use Metricool\Services\DashboardService;
11 12 use Metricool\Support\Helpers\Storages\EnvironmentConfig;
@@ -61,22 +62,12 @@
61 62 'newsletters' => $newsletters,
62 63 ], [
63 64 'RSPAL-RecaptchaV3Token' => $captcha
64 65 ]);
65 - } catch (Throwable $e) {
66 - throw new CreateAccountException(wp_kses_post($globalError), esc_html($e->getMessage()), 500);
66 + } catch (RestDataException $e) {
67 + throw new CreateAccountException(wp_kses_post($globalError), esc_html($e->getMessage()), $e->getResponseCode());
67 68 }
68 69
69 - // A 400 response means e-mail exists
70 - if ($signupResponse->getStatusCode() == 400) {
71 - throw new CreateAccountException(wp_kses_post($globalError), 'Email or password error', 422);
72 - }
73 -
74 - // Check if the response contains the required fields
75 - if (empty($signupResponse->data->accessToken) || empty($signupResponse->data->refreshToken)) {
76 - throw new CreateAccountException(wp_kses_post($globalError), 'Signup response is missing required fields', 500);
77 - }
78 -
79 70 // Parse the user ID from the access token
80 71 $userId = $this->oauth->parseUserIdFromAccessToken($signupResponse->data->accessToken);
81 72 if (empty($userId)) {
82 73 throw new CreateAccountException(wp_kses_post($globalError), 'Failed to parse user ID from access token', 500);
@@ -93,9 +84,9 @@
93 84 // Update the user's password
94 85 try {
95 86 $this->api->userCredentials()
96 87 ->updatePassword('', $password);
97 - } catch (Throwable $e) {
88 + } catch (ApiException $e) {
98 89 $this->api->logout();
99 90
100 91 throw new CreateAccountException(wp_kses_post($globalError), esc_html($e->getMessage()), 500);
101 92 }
@@ -103,9 +94,9 @@
103 94 // Attempt to automatically set the blog information, complete the onboarding process on success
104 95 try {
105 96 $this->onboarding->finalizeOnboarding($this->findConnectedBrandId());
106 97 } catch (Throwable $e) {
107 - throw new CreateAccountException(wp_kses_post($globalError), esc_html($e->getMessage()), 500);
98 + throw new CreateAccountException(wp_kses_post($globalError), esc_html($e->getMessage()), $e->getCode());
108 99 }
109 100
110 101 $this->dashboard->setShowWelcomeScreen();
111 102
@@ -114,9 +105,9 @@
114 105
115 106
116 107 /**
117 108 * Get the blogId from the API. This is needed to connect the brand and complete the onboarding process.
118 - * @throws GuzzleException
109 + * @throws ApiException
119 110 */
120 111 private function findConnectedBrandId(): ?string
121 112 {
122 113 $brands = $this->api->brands()->all();