add 新增SMS异常处理器
This commit is contained in:
parent
e181e340e4
commit
52a53791c8
@ -1,6 +1,7 @@
|
|||||||
package org.dromara.common.sms.config;
|
package org.dromara.common.sms.config;
|
||||||
|
|
||||||
import org.dromara.common.sms.core.dao.PlusSmsDao;
|
import org.dromara.common.sms.core.dao.PlusSmsDao;
|
||||||
|
import org.dromara.common.sms.handler.SmsExceptionHandler;
|
||||||
import org.dromara.sms4j.api.dao.SmsDao;
|
import org.dromara.sms4j.api.dao.SmsDao;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||||
@ -21,4 +22,12 @@ public class SmsAutoConfiguration {
|
|||||||
return new PlusSmsDao();
|
return new PlusSmsDao();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异常处理器
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public SmsExceptionHandler smsExceptionHandler() {
|
||||||
|
return new SmsExceptionHandler();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package org.dromara.common.sms.handler;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpStatus;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.common.core.domain.R;
|
||||||
|
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SMS异常处理器
|
||||||
|
*
|
||||||
|
* @author AprilWind
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class SmsExceptionHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sms异常
|
||||||
|
*/
|
||||||
|
@ExceptionHandler(SmsBlendException.class)
|
||||||
|
public R<Void> handleSmsBlendException(SmsBlendException e, HttpServletRequest request) {
|
||||||
|
String requestURI = request.getRequestURI();
|
||||||
|
log.error("请求地址'{}',发生sms短信异常.", requestURI, e);
|
||||||
|
return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, "短信发送失败,请稍后再试...");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user