diff --git a/common/models/Queue.php b/common/models/Queue.php index f1a844470..59ab1ac93 100644 --- a/common/models/Queue.php +++ b/common/models/Queue.php @@ -120,13 +120,14 @@ public function beforeSave($insert) { $this->queue_response = json_encode($createNewSiteResponse); + $message = 'Unable to create the site right now. Please try again later.'; + Yii::error('[Netlify > While Creating new site]' . json_encode($createNewSiteResponse->data), __METHOD__); + if (isset(Yii::$app->session->id)) { - Yii::$app->session->setFlash('error', '[Netlify > While Creating new site]' . json_encode($createNewSiteResponse->data)); + Yii::$app->session->setFlash('error', $message); } - $this->addError('restaurant_uuid', '[Netlify > While Creating new site]' . json_encode($createNewSiteResponse->data)); - - //Yii::error('[Netlify > While Creating new site]' . json_encode($createNewSiteResponse->data), __METHOD__); + $this->addError('restaurant_uuid', $message); return false; } @@ -134,13 +135,15 @@ public function beforeSave($insert) { } else{ $this->queue_response = json_encode($createBranchResponse); + $message = 'Unable to prepare the site repository right now. Please try again later.'; + $createBranchMessage = isset($createBranchResponse->data['message']) ? $createBranchResponse->data['message'] : null; + Yii::error('[Github > Create branch]' . json_encode($createBranchMessage) . ' RestaurantUuid: '. $store_model->restaurant_uuid. ' Named: '. $store_model->name, __METHOD__); + if (isset(Yii::$app->session->id)) { - Yii::$app->session->setFlash('error', '[Github > Create branch]' . json_encode($createBranchResponse->data['message']) . ' RestaurantUuid: ' . $store_model->restaurant_uuid); + Yii::$app->session->setFlash('error', $message); } - $this->addError('restaurant_uuid', '[Github > Create branch]' . json_encode($createBranchResponse->data['message']) . ' RestaurantUuid: '. $store_model->restaurant_uuid. ' Named: '. $store_model->name); - - //Yii::error('[Github > Create branch]' . json_encode($createBranchResponse->data['message']) . ' RestaurantUuid: '. $store_model->restaurant_uuid. ' Named: '. $store_model->name, __METHOD__); + $this->addError('restaurant_uuid', $message); return false; } @@ -148,13 +151,15 @@ public function beforeSave($insert) { } else { $this->queue_response = json_encode($getLastCommitResponse); + $message = 'Unable to prepare the site repository right now. Please try again later.'; + $lastCommitMessage = isset($getLastCommitResponse->data['message']) ? $getLastCommitResponse->data['message'] : null; + Yii::error('[Github > Last commit]' . json_encode($lastCommitMessage) . ' RestaurantUuid: '. $store_model->restaurant_uuid. ' Named: '. $store_model->name, __METHOD__); + if (isset(Yii::$app->session->id)) { - Yii::$app->session->setFlash('error', '[Github > Last commit]' . json_encode($getLastCommitResponse->data['message']) . ' RestaurantUuid: ' . $store_model->restaurant_uuid); + Yii::$app->session->setFlash('error', $message); } - $this->addError('restaurant_uuid', '[Github > Last commit]' . json_encode($getLastCommitResponse->data['message']) . ' RestaurantUuid: '. $store_model->restaurant_uuid. ' Named: '. $store_model->name); - - Yii::error('[Github > Last commit]' . json_encode($getLastCommitResponse->data['message']) . ' RestaurantUuid: '. $store_model->restaurant_uuid. ' Named: '. $store_model->name, __METHOD__); + $this->addError('restaurant_uuid', $message); return false; } diff --git a/tests/check-queue-provider-error-messages.sh b/tests/check-queue-provider-error-messages.sh new file mode 100644 index 000000000..81d4b1ff9 --- /dev/null +++ b/tests/check-queue-provider-error-messages.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -euo pipefail + +target="common/models/Queue.php" + +grep -q "Unable to create the site right now. Please try again later." "$target" +grep -q "Unable to prepare the site repository right now. Please try again later." "$target" +grep -q "Yii::error('\\[Netlify > While Creating new site\\]'" "$target" +grep -q "Yii::error('\\[Github > Create branch\\]'" "$target" +grep -q "Yii::error('\\[Github > Last commit\\]'" "$target" + +if grep -nE "setFlash\\('error'.*(Response->data|RestaurantUuid|Named:)" "$target"; then + echo "queue provider flash still exposes raw provider details" >&2 + exit 1 +fi + +if grep -nE "addError\\('restaurant_uuid'.*(Response->data|RestaurantUuid|Named:)" "$target"; then + echo "queue provider model error still exposes raw provider details" >&2 + exit 1 +fi + +echo "Queue provider error message guard passed."