-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathValidationErrorDto.cs
More file actions
124 lines (105 loc) · 4.76 KB
/
ValidationErrorDto.cs
File metadata and controls
124 lines (105 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
//
// Changes to this file may cause incorrect behavior and will be lost when
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
#nullable enable
namespace Novu.Models.Errors
{
using Newtonsoft.Json;
using Novu.Models.Components;
using Novu.Utils;
using System;
using System.Collections.Generic;
using System.Net.Http;
public class ValidationErrorDtoPayload
{
/// <summary>
/// HTTP status code of the error response.
/// </summary>
[JsonProperty("statusCode")]
public double StatusCode { get; set; } = default!;
/// <summary>
/// Timestamp of when the error occurred.
/// </summary>
[JsonProperty("timestamp")]
public string Timestamp { get; set; } = default!;
/// <summary>
/// The path where the error occurred.
/// </summary>
[JsonProperty("path")]
public string Path { get; set; } = default!;
/// <summary>
/// Optional context object for additional error details.
/// </summary>
[JsonProperty("ctx")]
public Dictionary<string, object>? Ctx { get; set; }
/// <summary>
/// Optional unique identifier for the error, useful for tracking using Sentry and <br/>
/// New Relic, only available for 500.
/// </summary>
[JsonProperty("errorId")]
public string? ErrorId { get; set; }
/// <summary>
/// A record of validation errors keyed by field name.
/// </summary>
[JsonProperty("errors")]
public Dictionary<string, ConstraintValidation> Errors { get; set; } = default!;
/// <summary>
/// Value that failed validation.
/// </summary>
[JsonProperty("message")]
public string? Message { get; set; }
}
public class ValidationErrorDto : BaseException
{
/// <summary>
/// The original data that was passed to this exception.
/// </summary>
public ValidationErrorDtoPayload Payload { get; }
[Obsolete("This field will be removed in a future release, please migrate away from it as soon as possible. Use ValidationErrorDto.Payload.StatusCode instead.")]
public double StatusCode { get; set; } = default!;
[Obsolete("This field will be removed in a future release, please migrate away from it as soon as possible. Use ValidationErrorDto.Payload.Timestamp instead.")]
public string Timestamp { get; set; } = default!;
[Obsolete("This field will be removed in a future release, please migrate away from it as soon as possible. Use ValidationErrorDto.Payload.Path instead.")]
public string Path { get; set; } = default!;
[Obsolete("This field will be removed in a future release, please migrate away from it as soon as possible. Use ValidationErrorDto.Payload.Ctx instead.")]
public Dictionary<string, object>? Ctx { get; set; }
[Obsolete("This field will be removed in a future release, please migrate away from it as soon as possible. Use ValidationErrorDto.Payload.ErrorId instead.")]
public string? ErrorId { get; set; }
[Obsolete("This field will be removed in a future release, please migrate away from it as soon as possible. Use ValidationErrorDto.Payload.Errors instead.")]
public Dictionary<string, ConstraintValidation> Errors { get; set; } = default!;
[Obsolete("This field will be removed in a future release, please migrate away from it as soon as possible. Use ValidationErrorDto.Payload.Message instead.")]
private string? _message { get; set; }
private static string ErrorMessage(ValidationErrorDtoPayload payload, string body)
{
string? message = payload.Message;
if (!string.IsNullOrEmpty(message))
{
return message;
}
return "API error occurred";
}
public ValidationErrorDto(
ValidationErrorDtoPayload payload,
HttpRequestMessage request,
HttpResponseMessage response,
string body
): base(ErrorMessage(payload, body), request, response, body)
{
Payload = payload;
#pragma warning disable CS0618
StatusCode = payload.StatusCode;
Timestamp = payload.Timestamp;
Path = payload.Path;
Ctx = payload.Ctx;
ErrorId = payload.ErrorId;
Errors = payload.Errors;
_message = payload.Message;
#pragma warning restore CS0618
}
}
}