proudmonkey / AutoWrapper

A simple, yet customizable global exception handler and Http response wrapper for ASP.NET Core APIs.
MIT License
677 stars 82 forks source link

How to get the error object is Pascal Case #148

Open RoLYroLLs opened 4 months ago

RoLYroLLs commented 4 months ago

I've been searching up and down the web, but maybe I'm not searching right so I've finally decided to ask here.

Is there a way to return the built-in error object in Pascal Case vs Camel Case?

It's probably bad practice on our part to use PascalCase for JSON, but we are ok with it for this particular project. Here's a test result we were testing. You'll notice only the properties within the ExceptionMessage object is in CamelCase.

{
    "Version": "2.0",
    "StatusCode": 415,
    "Message": null,
    "IsError": true,
    "ResponseException": {
        "ExceptionMessage": {
            "type": "https://tools.ietf.org/html/rfc7231#section-6.5.13",
            "title": "Unsupported Media Type",
            "status": 415,
            "traceId": "00-0d2fa91cddff04de600846d8e2d19746-7c76888436fbd052-00"
        },
        "Details": null,
        "ReferenceErrorCode": null,
        "ReferenceDocumentLink": null,
        "ValidationErrors": null
    },
    "Result": null
}

Here is our initializer

builder.UseApiResponseAndExceptionWrapper(new AutoWrapperOptions {
    UseCustomSchema = false,
    ShowStatusCode = true,
    ShowApiVersion = true,
    IgnoreNullValue = false,
    UseCamelCaseNamingStrategy = false,
    EnableExceptionLogging = false,
    EnableResponseLogging = false,
    LogRequestDataOnException = false,
});

Thanks in advance.