Use switch expression

pull/10366/head
Stepan Goremykin 12 months ago
parent f84469d500
commit 160855ffe9

@ -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)

Loading…
Cancel
Save