C
C#3y ago
barcode

Error validation [Answered]

[Required]
[MinLength(8, ErrorMessage = "Password too short")]
[MaxLength(32, ErrorMessage ="Password too long")]
public string Password { get; set; }
[Required]
[MinLength(8, ErrorMessage = "Password too short")]
[MaxLength(32, ErrorMessage ="Password too long")]
public string Password { get; set; }
I have this in my Dto and when validation is invalid I get this for example
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "00-7e6431d39d15726ab988a4d46bcfec16-79d8864992a8a975-00",
"errors": {
"Password": [
"Password too short"
]
}
}
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "00-7e6431d39d15726ab988a4d46bcfec16-79d8864992a8a975-00",
"errors": {
"Password": [
"Password too short"
]
}
}
11 Replies
barcode
barcodeOP3y ago
Is there a way to change Password to password in response because when I try retuning capital case myself like this
return BadRequest(new {Errors = new {Email = new string[]{"That email is already registered."}}});
return BadRequest(new {Errors = new {Email = new string[]{"That email is already registered."}}});
it gets snakecased and I can't have a consistent error check in my react app
barcode
barcodeOP3y ago
barcode
barcodeOP3y ago
response when I return it
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
barcode
barcodeOP3y ago
ty
barcode
barcodeOP3y ago
barcode
barcodeOP3y ago
it still get lowercased :[
var problemDetails = new ProblemDetails {
Detail = "Email already registered",
};
problemDetails.Extensions.Add("Errors", new List<Dictionary<string, string[]>> ()
{
new Dictionary<string, string[]>() {{"Email", new string[]{ "Email is already registered"}}}
});
return BadRequest(problemDetails);
var problemDetails = new ProblemDetails {
Detail = "Email already registered",
};
problemDetails.Extensions.Add("Errors", new List<Dictionary<string, string[]>> ()
{
new Dictionary<string, string[]>() {{"Email", new string[]{ "Email is already registered"}}}
});
return BadRequest(problemDetails);
my code
barcode
barcodeOP3y ago
barcode
barcodeOP3y ago
i just need the Email to be uppercase any way to enforce this ..? or to enforce it to be lowercase in validation dto
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Accord
Accord3y ago
✅ This post has been marked as answered!

Did you find this page helpful?