Exception Handling Availability Tactic - SENG-350-2024-fall/Team-1 GitHub Wiki
Source: app/frontend/src/context/AuthContext.jsx, Lines 30-48.
try {
const response = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body,
});
if (response.ok) {
setIsAuthenticated(true);
setUserType(userType);
navigate("/");
} else if (userType === "patient") {
setHealthCareNumber("");
}
} catch (error) {
console.error("Login failed:", error);
}
The Exception Handling Architecture Tactic for Availability is effectively used in the login
function within the AuthProvider
component. The try-catch
block around the API request handles any potential network or server errors, logging a message to the console if an error occurs. This ensures that unexpected issues during the login process, such as a failed network connection, do not crash the application or disrupt the user experience. This tactic is a good choice because it enhances the stability and reliability of the application. By catching exceptions, the code prevents crashes and allows the application to handle errors gracefully, ensuring a consistent experience for users. Exception handling is especially valuable in critical applications like healthcare, where consistent availability is essential, as it allows the system to recover smoothly from errors and maintain user confidence.