From 7fe2d0efd39af585195f0952acd42ec928d02f9b Mon Sep 17 00:00:00 2001 From: Dimitar Byalkov Date: Sat, 9 Apr 2022 06:05:11 +0300 Subject: [PATCH] Error handling for impossible time ranges --- RentACar/WebApp/Controllers/RentsController.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/RentACar/WebApp/Controllers/RentsController.cs b/RentACar/WebApp/Controllers/RentsController.cs index 6aff750..bf51b00 100644 --- a/RentACar/WebApp/Controllers/RentsController.cs +++ b/RentACar/WebApp/Controllers/RentsController.cs @@ -74,12 +74,12 @@ namespace WebApp.Controllers rents.User = user; _context.Add(rents); } - else throw new ArgumentOutOfRangeException("Selected car is unavailable at the chosen times."); + else throw new ArgumentException("Selected car is unavailable at the chosen times."); await _context.SaveChangesAsync(); } - catch (ArgumentOutOfRangeException e) + catch (ArgumentException e) { - byte[] data = Encoding.UTF8.GetBytes(e.ParamName + " Back"); + byte[] data = Encoding.UTF8.GetBytes(e.Message + " Back"); Response.ContentType = "text/html"; await Response.Body.WriteAsync(data, 0, data.Length); } @@ -122,7 +122,7 @@ namespace WebApp.Controllers _context.Update(rents); await _context.SaveChangesAsync(); } - else throw new ArgumentOutOfRangeException("Selected car is unavailable at the chosen times."); + else throw new ArgumentException("Selected car is unavailable at the chosen times."); } catch (DbUpdateConcurrencyException) { @@ -135,9 +135,9 @@ namespace WebApp.Controllers throw; } } - catch (ArgumentOutOfRangeException ex) + catch (ArgumentException ex) { - byte[] data = Encoding.UTF8.GetBytes(ex.ParamName + " Back"); + byte[] data = Encoding.UTF8.GetBytes(ex.Message + " Back"); Response.ContentType = "text/html"; await Response.Body.WriteAsync(data, 0, data.Length); }