Comments (3)
Good evening can't we make custom exception middleware and leave it to programmer handle the rest of it
We just need to make initial structure for in server side register it in program.
app.UseMiddleware<ErrorHandlerMiddleware>();
For example we can use some class for custom exception type
` public class HttpResponseException
{
public int? status { get; }
public object? internalError { get; }
public string? message { get; }
public string? code { get; }
public string? name { get; }
public HttpResponseException(int? status, object? internalError, string? message, string? code, string? name)
{
this.status = status;
this.internalError = internalError;
this.message = message;
this.code = code;
this.name = name;
}
}`
And write handler for it and leave it to programmer to handle it
` public class ErrorHandlerMiddleware
{
private readonly RequestDelegate _next;
private HttpResponseException httpResponseException { get; set; }
public ErrorHandlerMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
try
{
await _next(context);
}
catch (Exception ex)
{
var response = context.Response;
response.ContentType = "application/json";
switch (ex.Message)
{
case "err-404":
httpResponseException = new HttpResponseException(status: 400, internalError: ex.InnerException,
message: "Entity not found", code: ex.Message, name: "Bad Request");
break;
default:
httpResponseException = new HttpResponseException(status: 500, internalError: ex.InnerException,
message: ex.Message, code: ex.Message, name: "Internal Server Error");
break;
}
var result = JsonSerializer.Serialize(httpResponseException);
response.StatusCode = (int)httpResponseException.status;
await response.WriteAsync(result);
}
}
}`
So this way we could make custom Exceptions more like json api format ant it would be cleaner than throw 500 and some text
don't u think?
from stl.fusion.
And we should probably add it to the template
from stl.fusion.
@BokhodirUrinboev sorry, I noticed this comment very late. This approach certainly works, the "meta issue" was more about adding dedicated exception types for some of errors thrown by Fusion.
And v6 completely overhauled Fusion's communication stack replacing it with Stl.Rpc, so this approach is less necessary there: Stl.Rpc's default is to serialize the exception type & message automatically.
from stl.fusion.
Related Issues (20)
- Add MessagePack serializer support HOT 4
- Sign the assemblies that could be signed
- async alternate HOT 3
- [StateHasChangedAsync] System.NullReferenceException: 'Object reference not set to an instance of an object.' HOT 8
- infinite query loop HOT 7
- blazor wasm only (no server side blazor) can't get auth schemes HOT 3
- Exception when using together with Moq 4.18.1 HOT 9
- Don't mask HTTP errors in replica services HOT 1
- Improve test coverage
- A DateTime value was incorrectly passed to the server in Korean. HOT 2
- Commands are executed twice? HOT 3
- Could not load type 'Stl.Fusion.Bridge.IChannelProvider' from assembly 'Stl.Fusion
- Live sample at https://fusion-samples.servicetitan.com/ is broken in wasm mode HOT 2
- Assistance Needed: List Method Not Retrieving Values and Not Subscribing to Updates HOT 5
- Assistance/Improvement for Factories/Proxies using ActivatorUtilities HOT 7
- Stl.Interception gets trimmed away HOT 10
- Add Stl.Async-way of awaiting WaitHandle HOT 3
- thank you for developing, HOT 1
- Compared performance to gRPC with heavy payloads
- Error Using Session: System.InvalidOperationException: Property Session is not Initialized
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stl.fusion.