Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我抛出一个特定的错误时,我想返回一个特定的响应。示例:
对于像这样的投掷:
throw new NotAllowedForUnconfirmedEmail();
自动发送带有个性化数据的 json 响应,而无需在每个控制器中捕获。可能吗 ?
捕获异常后,您可以建立响应。请记住,这仅在发送任何输出之前有效。
try { throw new NotAllowedForUnconfirmedEmail(); } catch (NotAllowedForUnconfirmedEmail $e) { header("Content-Type: application/json"); $json = json_encode($personalizedData); echo $json; exit; }