Laravel Listener 中应不应该抛出异常?

好比我当前发布了一个评论, 发布之后需要请求敏感词过滤系统,

 public function sensitive($content)
    {
        $response = $this->getHttpClient()->post('api/analyzer/sensitive', [
            'form_params' => [
                'appId' => $this->appId,
                'content' => $content,
                'secret' => $this->secret,
                'type' => $this->type,
                'timestamp' => $this->timestamp,
                'sign' => $this->getSign()
            ]
        ]);

        if ($response->getStatusCode() != 200) {
            throw new Exception('连接词汇服务器失败');
        }

        $data = json_decode($response->getBody()->getContents(), true);

        if (!$data || $data['code'] != 0) {
            throw new Exception('获取词汇信息失败');
        }

        return $data['data']['target'];
    }

这里如果发现敏感词系统连接失败就会抛出异常.

DB::beginTransaction();

try {
    $comment = Comment::create([
        'article_id' => $article->id,
        'body' => $request->body,
        'create_user_id' => $request->user()->id,
        'create_nickname' => $request->user()->nickname,
        'create_avatar' => $request->user()->avatar
    ]);

    $article->increment('total_comment');

    event(new CommentCreated($comment));

    DB::commit();

    return responseSuccess($service->getSingleComment($comment, $request->user(), false));
} catch (Exception $e) {
    Log::error($e);
    DB::rollback();
    return responseError('发布评论异常');
}       

我想知道这个listener一般是会进行异常抛出吗,我感觉listener是不是不应该抛出异常, 但是我又想如果敏感词过滤失败的话就不发布, 代码一般大神们是怎么去做!

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!