Skip to content

Commit bbe1e57

Browse files
committed
MAGE-1201 Add clarity to ObjectID does not exist error
1 parent 0b74c89 commit bbe1e57

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Observer/RecommendSettings.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,23 @@ protected function shouldDisplayWarning(array $recommendationResponse): bool
178178
!array_key_exists('hits', $recommendationResponse);
179179
}
180180

181+
/**
182+
* If there is no model on the index then a 404 error should be returned
183+
* (which will cause the exception on the API call) because there is no model for that index
184+
* However errors which say "Index does not exist" are cryptic
185+
* This function serves to make this clearer to the user while also filtering out the possible
186+
* "ObjectID does not exist" error which can occur if the model does not contain the test product
187+
*/
181188
protected function getUserFriendlyRecommendApiErrorMessage(\Exception $e): string
182189
{
183190
$msg = $e->getMessage();
184-
if ($e->getCode() === 404 && !!preg_match('/index.*does not exist/i', $msg)) {
185-
$msg = (string) __("A trained model could not be found.");
191+
if ($e->getCode() === 404) {
192+
if (!!preg_match('/index.*does not exist/i', $msg)) {
193+
$msg = (string) __("A trained model could not be found.");
194+
}
195+
if (!!preg_match('/objectid does not exist/i', $msg)) {
196+
$msg = (string) __("Could not find test product in trained model.");
197+
}
186198
}
187199
return $msg;
188200
}

0 commit comments

Comments
 (0)