有沒有辦法攔截異常并向最終客戶顯示有意義的消息?我正在嘗試使用 spring AOP 授權(quán)我的 api,如果最終用戶無權(quán)訪問該 API,我將拋出異常。@Aspectpublic class AuthorizationAspect { @Pointcut("@annotation(AuthenticateAccount)") public void authorized() {} private boolean isAuthorized() { // logic to check is user is authorised to call the api } @Before("authorized()") public void beforeControllerCall(JoinPoint joinPoint) throws UnauthorizedException { if(!isAuthorized)) { throw new UnauthorizedException("You don't have rights over this API"); } }}通過拋出異常,我能夠阻止對 API 的訪問,但它不會(huì)返回我試圖拋出異常的有意義的消息。有沒有人處理過這樣的用例并且可以幫助我解決這個(gè)問題?
添加回答
舉報(bào)
0/150
提交
取消
