84 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Net;
 | |
| using Kreta.Core.Domain;
 | |
| using Kreta.Core.Enum;
 | |
| using Kreta.Resources;
 | |
| 
 | |
| namespace Kreta.Core.Exceptions
 | |
| {
 | |
|     public class BlException : Exception
 | |
|     {
 | |
|         public HttpStatusCode StatusCode { get; set; }
 | |
| 
 | |
|         public BlExceptionType ExceptionType { get; }
 | |
| 
 | |
|         public BlException(BlExceptionType exceptionType) : base(exceptionType.ToDisplayName() ?? ErrorResource.IsmeretlenHibaTortent)
 | |
|         {
 | |
|             ExceptionType = exceptionType;
 | |
|         }
 | |
| 
 | |
|         public BlException(string message) : base(message)
 | |
|         {
 | |
|         }
 | |
| 
 | |
|         public BlException(string message, HttpStatusCode statusCode) : base(message)
 | |
|         {
 | |
|             StatusCode = statusCode;
 | |
|         }
 | |
| 
 | |
|         public BlException(string message, Exception exception) : base(message)
 | |
|         {
 | |
|             UnHandledException = exception;
 | |
|         }
 | |
| 
 | |
|         public BlException(string message, BlExceptionType exceptionType) : base(message)
 | |
|         {
 | |
|             ExceptionType = exceptionType;
 | |
|         }
 | |
| 
 | |
|         public BlException(string message, BlExceptionType exceptionType, Exception exception) : base(message)
 | |
|         {
 | |
|             ExceptionType = exceptionType;
 | |
|             UnHandledException = exception;
 | |
|         }
 | |
| 
 | |
|         public List<DetailedErrorItem> ErrorList { get; set; } = new List<DetailedErrorItem>();
 | |
| 
 | |
|         //Exception filter miatt raktam bele, ezeket a hibákat külön leloggolja, ha beleforgatjuk a StatusError-ba
 | |
|         public Exception UnHandledException { get; }
 | |
| 
 | |
|         public bool IsUnHandled => InnerException != null;
 | |
| 
 | |
|         private static readonly Dictionary<BlExceptionType, HttpStatusCode> ResponseStatusCodeLookUpTable
 | |
|         = new Dictionary<BlExceptionType, HttpStatusCode>
 | |
|         {
 | |
|                 { BlExceptionType.NemLetezoEntitas, HttpStatusCode.NotFound },
 | |
|                 { BlExceptionType.ModelValidacio, HttpStatusCode.BadRequest },
 | |
|                 { BlExceptionType.NincsJogosultsag, HttpStatusCode.Forbidden },
 | |
|                 { BlExceptionType.TulSokVisszateresiElem, HttpStatusCode.InternalServerError },
 | |
|                 { BlExceptionType.ValtozoErtekeNemLehetNull, HttpStatusCode.InternalServerError },
 | |
|                 { BlExceptionType.None, HttpStatusCode.InternalServerError },
 | |
|                 { BlExceptionType.ListaNemTartalmazElemet, HttpStatusCode.InternalServerError },
 | |
|                 { BlExceptionType.IntezmenyMarTanevetValtott, HttpStatusCode.Conflict },
 | |
|                 { BlExceptionType.IntezmenyAzonositoUtkozes, HttpStatusCode.Conflict },
 | |
|                 { BlExceptionType.AzonositoUtkozes, HttpStatusCode.Conflict },
 | |
|                 { BlExceptionType.ElvartErtekNemTalalhato, HttpStatusCode.InternalServerError },
 | |
|                 { BlExceptionType.ListaTobbMint50ElemetTartalmaz, HttpStatusCode.BadRequest },
 | |
|                 { BlExceptionType.AMuveletNemVegezhetoElTobbszor, HttpStatusCode.BadRequest },
 | |
|                 { BlExceptionType.DuplikaltKulcs, HttpStatusCode.InternalServerError },
 | |
|                 { BlExceptionType.NaploZaras, HttpStatusCode.BadRequest },
 | |
|                 { BlExceptionType.TaskCancelled, HttpStatusCode.BadRequest },
 | |
|                 { BlExceptionType.FunkcioKikapcsolva, HttpStatusCode.BadRequest }
 | |
|         };
 | |
| 
 | |
|         public HttpStatusCode GetResponseStatusCode()
 | |
|         {
 | |
|             return StatusCode == 0 ? ResponseStatusCodeLookUpTable.TryGetValue(ExceptionType, out HttpStatusCode statusCode)
 | |
|                 ? statusCode
 | |
|                 : HttpStatusCode.InternalServerError
 | |
|                 : StatusCode;
 | |
|         }
 | |
|     }
 | |
| }
 |