refactor: 重构异常处理
This commit is contained in:
@@ -22,10 +22,11 @@ const useUserStore = defineStore('user',
|
|||||||
const code = userInfo.code
|
const code = userInfo.code
|
||||||
const uuid = userInfo.uuid
|
const uuid = userInfo.uuid
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
login(userName, password, code, uuid).then(res => {
|
login(userName, password, code, uuid).then(response => {
|
||||||
|
const res=response.data;
|
||||||
setToken(res.token);
|
setToken(res.token);
|
||||||
this.token = res.token;
|
this.token = res.token;
|
||||||
resolve(res);
|
resolve(response);
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
reject(error)
|
reject(error)
|
||||||
})
|
})
|
||||||
@@ -35,7 +36,7 @@ const useUserStore = defineStore('user',
|
|||||||
getInfo() {
|
getInfo() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
getInfo().then(response => {
|
getInfo().then(response => {
|
||||||
const res=response;
|
const res=response.data;
|
||||||
const user = res.user
|
const user = res.user
|
||||||
const avatar = (user.icon == "" || user.icon == null) ? "/src/assets/logo.ico" : import.meta.env.VITE_APP_BASEAPI + "/file/"+user.icon;
|
const avatar = (user.icon == "" || user.icon == null) ? "/src/assets/logo.ico" : import.meta.env.VITE_APP_BASEAPI + "/file/"+user.icon;
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ myaxios.interceptors.request.use(function (config) {
|
|||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
myaxios.interceptors.response.use(function (response) {
|
myaxios.interceptors.response.use(function (response) {
|
||||||
|
|
||||||
return response.data;
|
return response;
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,10 +26,15 @@ const guestlogin=async ()=>{
|
|||||||
}
|
}
|
||||||
const login=async ()=>{
|
const login=async ()=>{
|
||||||
const response= await userStore.login(loginForm);
|
const response= await userStore.login(loginForm);
|
||||||
if( response.code==undefined)
|
console.log(response);
|
||||||
|
if( response.status==200)
|
||||||
{
|
{
|
||||||
router.push("/index")
|
router.push("/index")
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
alert("登录失败")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Core.Enums;
|
||||||
using Yi.Framework.Core.Exceptions;
|
using Yi.Framework.Core.Exceptions;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Builder
|
namespace Microsoft.AspNetCore.Builder
|
||||||
@@ -37,7 +38,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||||||
catch (BusinessException businessEx)
|
catch (BusinessException businessEx)
|
||||||
{
|
{
|
||||||
context.Response.ContentType = "application/json;charset=utf-8";
|
context.Response.ContentType = "application/json;charset=utf-8";
|
||||||
//context.Response.StatusCode = businessEx.Code.GetHashCode();
|
context.Response.StatusCode = (int)ResultCodeEnum.Denied;
|
||||||
|
|
||||||
var result = new ExceptionModle
|
var result = new ExceptionModle
|
||||||
{
|
{
|
||||||
@@ -59,7 +60,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||||||
//系统错误,记录日志
|
//系统错误,记录日志
|
||||||
_logger.LogError(ex, $"授权失败:{ex.Message}");
|
_logger.LogError(ex, $"授权失败:{ex.Message}");
|
||||||
//await _errorHandle.Invoer(context, ex);
|
//await _errorHandle.Invoer(context, ex);
|
||||||
context.Response.StatusCode = (int)ex.Code;
|
context.Response.StatusCode = (int)ResultCodeEnum.NoPermission;
|
||||||
//系统错误,需要记录
|
//系统错误,需要记录
|
||||||
var result = new ExceptionModle
|
var result = new ExceptionModle
|
||||||
{
|
{
|
||||||
@@ -80,7 +81,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||||||
//系统错误,记录日志
|
//系统错误,记录日志
|
||||||
_logger.LogError(ex, $"系统错误:{ex.Message}");
|
_logger.LogError(ex, $"系统错误:{ex.Message}");
|
||||||
//await _errorHandle.Invoer(context, ex);
|
//await _errorHandle.Invoer(context, ex);
|
||||||
context.Response.StatusCode = 500;
|
context.Response.StatusCode = (int)ResultCodeEnum.NotSuccess;
|
||||||
//系统错误,需要记录
|
//系统错误,需要记录
|
||||||
var result = new ExceptionModle
|
var result = new ExceptionModle
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ namespace Yi.Framework.Core.Enums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 无权限
|
/// 无权限
|
||||||
/// </summary>
|
/// </summary>
|
||||||
NoPermission = 401
|
NoPermission = 401,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 被拒绝
|
||||||
|
/// </summary>
|
||||||
|
Denied = 403
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace Yi.Framework.Core.Exceptions
|
|||||||
public LogLevel LogLevel { get; set; }
|
public LogLevel LogLevel { get; set; }
|
||||||
|
|
||||||
public BusinessException(
|
public BusinessException(
|
||||||
int code = (int)ResultCodeEnum.NotSuccess,
|
int code = (int)ResultCodeEnum.Denied,
|
||||||
string? message = null,
|
string? message = null,
|
||||||
string? details = null,
|
string? details = null,
|
||||||
Exception? innerException = null,
|
Exception? innerException = null,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace Yi.Framework.Core.Exceptions
|
|||||||
{
|
{
|
||||||
public UserFriendlyException(
|
public UserFriendlyException(
|
||||||
string message,
|
string message,
|
||||||
int code = (int)ResultCodeEnum.NotSuccess,
|
int code = (int)ResultCodeEnum.Denied,
|
||||||
string? details = null,
|
string? details = null,
|
||||||
Exception? innerException = null,
|
Exception? innerException = null,
|
||||||
LogLevel logLevel = LogLevel.Warning)
|
LogLevel logLevel = LogLevel.Warning)
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user