Fix error code when context not found

parent d5a80353
...@@ -138,6 +138,8 @@ abstract class TyposClientInterface ...@@ -138,6 +138,8 @@ abstract class TyposClientInterface
private function replaceTypoInArticle(string $typo, string $corrected, string $context, TyposArticle $article) { private function replaceTypoInArticle(string $typo, string $corrected, string $context, TyposArticle $article) {
$lastException = null; $lastException = null;
$isContextNotFound = false;
// Replace -- to - in context string // Replace -- to - in context string
// BUG# 12799 // BUG# 12799
$context = str_replace("\xe2\x80\x94", "-", $context); $context = str_replace("\xe2\x80\x94", "-", $context);
...@@ -149,9 +151,17 @@ abstract class TyposClientInterface ...@@ -149,9 +151,17 @@ abstract class TyposClientInterface
return; return;
} catch (\Exception $e) { } catch (\Exception $e) {
error_log($e->getMessage()); error_log($e->getMessage());
if ($e->getCode() != 404 && $e->getCode() != 405) { if ($e->getCode() != 404 && $e->getCode() != 405) {
throw $e; throw $e;
} }
// If context was not found in text then remember this
// and after all search if we not found a typo, then throw
// 405 exception and not 404
if ($e->getCode() == 405) {
$isContextNotFound = true;
}
} }
// Trying to replace typo in title // Trying to replace typo in title
...@@ -161,14 +171,27 @@ abstract class TyposClientInterface ...@@ -161,14 +171,27 @@ abstract class TyposClientInterface
return; return;
} catch (\Exception $e) { } catch (\Exception $e) {
error_log($e->getMessage()); error_log($e->getMessage());
if ($e->getCode() != 404 && $e->getCode() != 405) { if ($e->getCode() != 404 && $e->getCode() != 405) {
throw $e; throw $e;
} }
if ($e->getCode() == 405) {
$isContextNotFound = true;
}
} }
error_log("Trying to find a typo in article subtitle...");
// Trying to replace typo in subtitle // Trying to replace typo in subtitle
try {
error_log("Trying to find a typo in article subtitle...");
$article->subtitle = $this->replaceTypoInText($typo, $corrected, $context, $article->subtitle); $article->subtitle = $this->replaceTypoInText($typo, $corrected, $context, $article->subtitle);
} catch (\Exception $e) {
if ($e->getCode() == 404 && $isContextNotFound) {
throw new \Exception("Context not found", 405);
}
throw $e;
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment