密码错误默认的异常信息如下

账号无效的异常

这里的无效用户 是我在程序中抛出来异常,默认也不这样, 但是不管怎么, 都不是我们想要的, 我想返回给前端自定义的,比如 有status,code msg 等等,
自定义 MyWebResponseExceptionTranslator 实现 WebResponseExceptionTranslator
package com.yyc.platform.uaa.config;
import com.yyc.platform.common.utils.JsonResult;
import com.yyc.platform.uaa.exception.UserNotFountException;
import org.omg.CORBA.DynAnyPackage.Invalid;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
import org.springframework.security.oauth2.common.exceptions.OAuth2Except

本文介绍如何在OAuth2框架中自定义异常处理,通过创建MyWebResponseExceptionTranslator类实现WebResponseExceptionTranslator接口,针对不同异常类型如无效授权码、无效用户、密码错误和无效token,返回定制化的JSON响应。同时,提供了自定义JsonResult类用于统一前端返回结果。
最低0.47元/天 解锁文章
4385





