Skip to content

Commit a9994c7

Browse files
committed
update error handling & trim value before encrypting
1 parent 3074abd commit a9994c7

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

prestashop1.7/controllers/admin/AdminTawktoController.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,20 @@ private function processSetOptions(string $params): array
320320
break;
321321
}
322322

323-
try {
324-
if (strlen(trim($value)) !== 40) {
325-
throw new Exception('Invalid API key. Please provide value with 40 characters');
326-
}
323+
$value = trim($value);
324+
325+
if (strlen($value) !== 40) {
326+
throw new Exception('Invalid API key.');
327+
}
327328

329+
try {
328330
$jsonOpts['js_api_key'] = $this->encryptData($value);
329331
} catch (Exception $e) {
332+
error_log($e->getMessage());
333+
330334
unset($jsonOpts['js_api_key']);
331335

332-
throw new Exception('Javascript API Key: ' . $e->getMessage());
336+
throw new Exception('Error saving Javascript API Key.');
333337
}
334338

335339
break;

prestashop8.x/controllers/admin/AdminTawktoController.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,20 @@ private function processSetOptions(string $params): array
320320
break;
321321
}
322322

323-
try {
324-
if (strlen(trim($value)) !== 40) {
325-
throw new Exception('Invalid API key. Please provide value with 40 characters');
326-
}
323+
$value = trim($value);
324+
325+
if (strlen($value) !== 40) {
326+
throw new Exception('Invalid API key.');
327+
}
327328

329+
try {
328330
$jsonOpts['js_api_key'] = $this->encryptData($value);
329331
} catch (Exception $e) {
332+
error_log($e->getMessage());
333+
330334
unset($jsonOpts['js_api_key']);
331335

332-
throw new Exception('Javascript API Key: ' . $e->getMessage());
336+
throw new Exception('Error saving Javascript API Key.');
333337
}
334338

335339
break;

0 commit comments

Comments
 (0)