| | | 1 | | using Microsoft.AspNetCore.Mvc.ModelBinding; |
| | | 2 | | using Newtonsoft.Json; |
| | | 3 | | using System; |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | using System.Linq; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | |
| | | 8 | | namespace SVETA.Api.Data.DTO |
| | | 9 | | { |
| | | 10 | | // Класс для возврата ошибки на проде |
| | | 11 | | public class ErrorSimpleDto |
| | | 12 | | { |
| | 0 | 13 | | public string error { get; set; } |
| | 0 | 14 | | public int code { get; set; } |
| | 0 | 15 | | public string detailLink { get; set; } |
| | | 16 | | |
| | 0 | 17 | | public ErrorSimpleDto(string message) |
| | 0 | 18 | | { |
| | 0 | 19 | | error = message; |
| | 0 | 20 | | } |
| | | 21 | | public override string ToString() |
| | 0 | 22 | | { |
| | 0 | 23 | | return JsonConvert.SerializeObject(this); |
| | 0 | 24 | | } |
| | | 25 | | } |
| | | 26 | | public class ErrorDTO |
| | | 27 | | { |
| | | 28 | | public ErrorDTO() |
| | | 29 | | { |
| | | 30 | | |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | public ErrorDTO(string message) |
| | | 34 | | { |
| | | 35 | | error = message; |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | public ErrorDTO(Exception ex) |
| | | 39 | | { |
| | | 40 | | error = $"{ex.Message} (Код ошибки: {ex.Data["errorcode"]})"; |
| | | 41 | | stackTrace = ex.StackTrace; |
| | | 42 | | innerError = ex.InnerException?.Message; |
| | | 43 | | innerStackTrace = ex.InnerException?.StackTrace; |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | public ErrorDTO(ModelStateDictionary modelState) |
| | | 47 | | { |
| | | 48 | | error = string.Join(", ", modelState.Keys |
| | | 49 | | .SelectMany(key => modelState[key].Errors.Select(x => x.ErrorMessage)) |
| | | 50 | | .ToList()); |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | public string error { get; set; } |
| | | 54 | | |
| | | 55 | | public int code { get; set; } |
| | | 56 | | |
| | | 57 | | public string stackTrace { get; set; } |
| | | 58 | | |
| | | 59 | | public string innerError { get; set; } |
| | | 60 | | |
| | | 61 | | public string innerStackTrace { get; set; } |
| | | 62 | | |
| | | 63 | | public string detailLink { get; set; } |
| | | 64 | | |
| | | 65 | | public override string ToString() |
| | | 66 | | { |
| | | 67 | | return JsonConvert.SerializeObject(this); |
| | | 68 | | } |
| | | 69 | | } |
| | | 70 | | } |