Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Exception): Add ErrorCode to support multiple languages later #174

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

using Masa.Utils.Exceptions.Handlers;

namespace Microsoft.AspNetCore.Builder;

public static class ApplicationBuilderExtensions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Utils.Exceptions.Handlers;
namespace Microsoft.AspNetCore.Builder;

public class ExceptionHandlerMiddleware
{
Expand All @@ -20,7 +20,10 @@ public ExceptionHandlerMiddleware(
{
_next = next;
_options = options.Value;
_masaExceptionHandler = ExceptionHandlerExtensions.GetMasaExceptionHandler(serviceProvider, _options.MasaExceptionHandlerType);
_masaExceptionHandler =
Masa.Utils.Exceptions.Internal.ExceptionHandlerExtensions.GetMasaExceptionHandler(
serviceProvider,
_options.MasaExceptionHandlerType);
_logRelationOptions = logRelationOptions.Value;
_logger = logger;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Utils.Exceptions.Handlers;
namespace Microsoft.AspNetCore.Builder;

public class ExceptionHandlingMiddleware
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Utils.Exceptions.Handlers;
namespace Microsoft.AspNetCore.Mvc.Filters;

/// <summary>
/// Mvc pipeline exception filter to catch global exception
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Masa.Utils.Exceptions/IMasaExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Utils.Exceptions;
namespace System;

public interface IMasaExceptionHandler
{
Expand Down
16 changes: 15 additions & 1 deletion src/Utils/Masa.Utils.Exceptions/MasaException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class MasaException : Exception
{
public string? ErrorCode { get; set; }

public object[] Parameters { get; set; }

public MasaException()
{
}
Expand All @@ -16,7 +18,19 @@ public MasaException(string message)
{
}

public MasaException(string message, Exception innerException)
public MasaException(string errorCode, params object[] parameters)
: this(null, errorCode, parameters)
{
}

public MasaException(Exception? innerException, string errorCode, params object[] parameters)
: base(null, innerException)
{
ErrorCode = errorCode;
Parameters = parameters;
}

public MasaException(string message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Utils.Exceptions;
namespace System;

public class MasaExceptionHandlerOptions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Utils.Exceptions;
namespace System;

public class MasaExceptionHandlingOptions
{
Expand Down
15 changes: 15 additions & 0 deletions src/Utils/Masa.Utils.Exceptions/UserFriendlyException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,19 @@ public UserFriendlyException(string message)
: base(message)
{
}

public UserFriendlyException(string message, Exception? innerException)
: base(message, innerException)
{
}

public UserFriendlyException(string errorCode, params object[] parameters)
: base(errorCode, parameters)
{
}

public UserFriendlyException(Exception? innerException, string errorCode, params object[] parameters)
: base(innerException, errorCode, parameters)
{
}
}
1 change: 0 additions & 1 deletion src/Utils/Masa.Utils.Exceptions/_Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

global using Masa.Utils.Exceptions;
global using Masa.Utils.Exceptions.Handlers;
global using Masa.Utils.Exceptions.Internal;
global using Microsoft.AspNetCore.Http;
global using Microsoft.AspNetCore.Mvc;
Expand Down