ユーザー登録時グループを選択せず保存した場合のエラーメッセージに「 データベース処理中にエラーが発生しました。」と表示される件を修正#4478
ユーザー登録時グループを選択せず保存した場合のエラーメッセージに「 データベース処理中にエラーが発生しました。」と表示される件を修正#4478otsuka-star wants to merge 1 commit into
Conversation
…ください。」から「ユーザーグループを指定してください。」になるように修正
| } catch (\Cake\ORM\Exception\PersistenceFailedException $e) { | ||
| $user = $e->getEntity(); | ||
| $this->BcMessage->setError(__d('baser_core', '入力エラーです。内容を修正してください。')); | ||
| } catch (BcException $e) { |
There was a problem hiding this comment.
BcException とThrowableの例外を表記修正のためだけに使い分けている例がコアだとかなり少ない気がするのですが...一応コア側の実装も確認されましたか?
表記を調整するためにそこまでやるのか、少し疑問に思いました。
管理画面とWEBAPI側
There was a problem hiding this comment.
こちら調べてみると、ユーザーグループ削除の際の①-1: Api/Admin/UserGroupsController.php:149-153行目と①-2: Admin/UserGroupsController.php:149-153行目、ブログコメントの登録時の②-1: plugins/bc-blog/src/Controller/BlogController.php:339-348行目と②-2: plugins/bc-blog/src/Controller/Api/Admin/BlogCommentsController.php:193-199行目などで、BcExceptionとThrowableの例外を表記修正のために使い分けが行われていますが、このパターンを取り入れる形で宜しいでしょうか?
①-1:
} catch (BcException $e) {
$this->BcMessage->setError($e->getMessage());
} catch (\Throwable $e) {
$this->BcMessage->setError(__d('baser_core', 'データベース処理中にエラーが発生しました。'));
}
①-2:
} catch (BcException $e) {
$this->setResponse($this->response->withStatus(400));
$message = $e->getMessage();
} catch (\Throwable $e) {
$message = __d('baser_core', 'データベース処理中にエラーが発生しました。') . $e->getMessage();
$this->setResponse($this->response->withStatus(500));
}
②-1:
} catch (BcException $e) {
$message = $e->getMessage();
return $this->response->withStatus(400)->withStringBody(json_encode([
'message' => $message
]));
} catch (Throwable $e) {
$message = __d('baser_core', 'データベース処理中にエラーが発生しました。') . $e->getMessage();
return $this->response->withStatus(500)->withStringBody(json_encode([
'message' => $message
]));
②-2:
} catch (BcException $e) {
$message = $e->getMessage();
$this->setResponse($this->response->withStatus(400));
} catch (Throwable $e) {
$message = __d('baser_core', 'データベース処理中にエラーが発生しました。') . $e->getMessage();
$this->setResponse($this->response->withStatus(500));
}
There was a problem hiding this comment.
@otsuka-star こちらの件、ユーザーグループのバリデーションの問題ですので、UsersService 側で、BcExceptionを投げているのが間違いですね。PersistenceFailedException を投げる仕様に調整すべきです。
| } catch (\Cake\ORM\Exception\PersistenceFailedException $e) { | ||
| $user = $e->getEntity(); | ||
| $this->BcMessage->setError(__d('baser_core', '入力エラーです。内容を修正してください。')); | ||
| } catch (BcException $e) { |
There was a problem hiding this comment.
こちらを追加するなら...
ユーザーグループコントローラーと同じようにWEB API側も追加するべきでは無いでしょうか?
新規追加と更新
なお、別PRで対応いただく形で認識していれば、問題ありませんが念の為記載します。
|
@otsuka-star 回答いれています |
@ryuring
こちらのレビューをお願い致します。
改修内容:
ユーザー登録時にグループを選択せず保存した場合のエラーメッセージを「 データベース処理中にエラーが発生しました。ユーザーグループを指定してください。」→「ユーザーグループを指定してください。」へ修正
要因:
ユーザー登録時(
UsersController::add())のcatchがPersistenceFailedExceptionとThrowableの2種類しか分岐しておらず、BcExceptionがThrowableの派生型のようなので後者のThrowableのcatchが適用され「 データベース処理中にエラーが発生しました。」というエラーメッセージが表示されているようでした。改修方法:
catch (BcException $e)をPersistenceFailedExceptionと\Throwableの間に追加し、「ユーザーグループを指定してください。」というエラーメッセージのみ表示されるようにいたしました。