Skip to content

Commit

Permalink
Error redirections
Browse files Browse the repository at this point in the history
  • Loading branch information
KaloyankerR committed Dec 17, 2023
1 parent a54de1c commit 458444c
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 26 deletions.
5 changes: 3 additions & 2 deletions FitFusion/FitFusionWeb/Pages/Account.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace FitFusionWeb.Pages
{
public class AccountModel : PageModel
{
[BindProperty]
public User CurrentUser { get; set; }

Check warning on line 16 in FitFusion/FitFusionWeb/Pages/Account.cshtml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'CurrentUser' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 16 in FitFusion/FitFusionWeb/Pages/Account.cshtml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'CurrentUser' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
private UserManager _userManager = new(new DataAcess.UserDAO());

Expand Down Expand Up @@ -44,11 +45,11 @@ public IActionResult OnGet()
}
catch (DataAccessException)
{
return RedirectToPage("/CustomPages/DatabaseConnectionError");
return RedirectToPage("/Error", new { code = 500 });
}
catch (NullReferenceException)
{
return RedirectToPage("/CustomPages/NotFound");
return RedirectToPage("/Error", new { code = 404 });
}

return RedirectToPage("/Authentication/Login");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public IActionResult OnPost()
catch (NullReferenceException)
{
// return RedirectToPage("/CustomPages/NotFound");
return RedirectToPage("/Error", new { code = 400 });
return RedirectToPage("/Error", new { code = 404 });
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,15 @@ public IActionResult OnPost()
catch (DuplicateNameException)
{
return RedirectToPage("/CustomPages/SomethingWentWrong");
// redirect to the correct page
// TODO: redirect to the correct page
}
catch (DataAccessException)
{
return RedirectToPage("/CustomPages/SomethingWentWrong");
// redirect to the correct page
return RedirectToPage("/Error", new { code = 500 });
}
catch (Exception)
catch
{
return RedirectToPage("/CustomPages/SomethingWentWrong");
return RedirectToPage("/Error");
}

return Page();
Expand Down
5 changes: 3 additions & 2 deletions FitFusion/FitFusionWeb/Pages/Cart.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ public IActionResult OnPost()
}
catch (DataAccessException)
{
return RedirectToPage("/CustomPages/DatabaseConnectionError");
return RedirectToPage("/Error", new { code = 500 });
}
catch (ArithmeticException)
{
//TODO: Make exception for this
return RedirectToPage("/CustomPages/NotEnoughNutriPoints");
}

SessionHelper.SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", new ShoppingCart());

// TODO: Make pages for information about the data provided
return RedirectToPage("/CustomPages/SuccessfulOrder");
}

Expand Down
3 changes: 0 additions & 3 deletions FitFusion/FitFusionWeb/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ public IndexModel(ILogger<IndexModel> logger)

public void OnGet()
{
OrderManager manager = new(new OrderDAO());


}

}
Expand Down
4 changes: 2 additions & 2 deletions FitFusion/FitFusionWeb/Pages/Products/All.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public IActionResult OnGet()
}
catch (DataAccessException)
{
return RedirectToPage("/CustomPages/DatabaseConnectionError");
return RedirectToPage("/Error", new { code = 500 });
}

return Page();
Expand All @@ -47,7 +47,7 @@ public IActionResult OnPost()
}
catch (DataAccessException)
{
return RedirectToPage("/CustomPages/DatabaseConnectionError");
return RedirectToPage("/Error", new { code = 500 });
}

return Page();
Expand Down
5 changes: 3 additions & 2 deletions FitFusion/FitFusionWeb/Pages/Products/Create.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace FitFusionWeb.Pages.Products
public class CreateModel : PageModel
{
[BindProperty]
public Product Product { get; set; }
public Product Product { get; set; } = new();
private readonly ProductManager _productManager = new(new DataAcess.ProductDAO());

public void OnGet()
Expand Down Expand Up @@ -42,12 +42,13 @@ public IActionResult OnPost()
}
catch (DataAccessException)
{
return RedirectToPage("/CustomPages/DatabaseConnectionError");
return RedirectToPage("/Error", new { code = 500 });
}
catch (DuplicateNameException)
{
TempData["Type"] = "danger";
TempData["Message"] = "Something went wrong!";
// TODO: write a better message
}


Expand Down
8 changes: 4 additions & 4 deletions FitFusion/FitFusionWeb/Pages/Products/Product.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ProductModel : PageModel
[BindProperty(SupportsGet = true)]
public int Id { get; set; }
[BindProperty]
public Product Product { get; set; }
public Product Product { get; set; } = new();
private readonly ProductManager _productManager = new ProductManager(new DataAcess.ProductDAO());

public IActionResult OnGet()
Expand All @@ -22,15 +22,15 @@ public IActionResult OnGet()
}
catch (DataAccessException)
{
return RedirectToPage("/CustomPages/DatabaseConnectionError");
return RedirectToPage("/Error", new { code = 500 });
}
catch (NullReferenceException)
{
return RedirectToPage("/CustomPages/NotFound");
return RedirectToPage("/Error", new { code = 404 });
}
catch
{
return RedirectToPage("/CustomPages/SomethingWentWrong");
return RedirectToPage("/Error");
}

return Page();
Expand Down
8 changes: 4 additions & 4 deletions FitFusion/FitFusionWeb/Pages/Products/Update.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class UpdateModel : PageModel
[BindProperty(SupportsGet = true)]
public int Id { get; set; }
[BindProperty]
public Product Product { get; set; }
private readonly ProductManager _productManager = new ProductManager(new DataAcess.ProductDAO());
public Product Product { get; set; } = new();
private readonly ProductManager _productManager = new (new DataAcess.ProductDAO());

public IActionResult OnGet()
{
Expand All @@ -22,11 +22,11 @@ public IActionResult OnGet()
}
catch (DataAccessException)
{
return RedirectToPage("/CustomPages/DatabaseConnectionError");
return RedirectToPage("/Error", new { code = 500 });
}
catch (NullReferenceException)
{
return RedirectToPage("/CustomPages/NotFound");
return RedirectToPage("/Error", new { code = 404 });
}

return Page();
Expand Down
3 changes: 2 additions & 1 deletion FitFusion/FitFusionWeb/SessionHelper/SessionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public static void SetObjectAsJson(this ISession session, string key, object val
public static T GetObjectFromJson<T>(this ISession session, string key)
{
var value = session.GetString(key);
return value == null ? default(T) : JsonConvert.DeserializeObject<T>(value);
// TODO: Check the null reference
return value == null ? default(T)! : JsonConvert.DeserializeObject<T>(value)!;
}

}
Expand Down

0 comments on commit 458444c

Please sign in to comment.