Use switch expression

This commit is contained in:
Stepan Goremykin 2023-10-08 00:52:47 +02:00
parent f84469d500
commit 160855ffe9
1 changed files with 10 additions and 10 deletions

View File

@ -122,17 +122,17 @@ public class ExceptionMiddleware
private static int GetStatusCode(Exception ex) private static int GetStatusCode(Exception ex)
{ {
switch (ex) return ex switch
{ {
case ArgumentException _: return StatusCodes.Status400BadRequest; ArgumentException => StatusCodes.Status400BadRequest,
case AuthenticationException _: return StatusCodes.Status401Unauthorized; AuthenticationException => StatusCodes.Status401Unauthorized,
case SecurityException _: return StatusCodes.Status403Forbidden; SecurityException => StatusCodes.Status403Forbidden,
case DirectoryNotFoundException _: DirectoryNotFoundException => StatusCodes.Status404NotFound,
case FileNotFoundException _: FileNotFoundException => StatusCodes.Status404NotFound,
case ResourceNotFoundException _: return StatusCodes.Status404NotFound; ResourceNotFoundException => StatusCodes.Status404NotFound,
case MethodNotAllowedException _: return StatusCodes.Status405MethodNotAllowed; MethodNotAllowedException => StatusCodes.Status405MethodNotAllowed,
default: return StatusCodes.Status500InternalServerError; _ => StatusCodes.Status500InternalServerError
} };
} }
private string NormalizeExceptionMessage(string msg) private string NormalizeExceptionMessage(string msg)