Exception Prevention Availability Tactic - SENG-350-2024-fall/Team-1 GitHub Wiki
Source: app/frontend/src/context/AuthContext.jsx, Lines 20-28.
if (userType === "staff") { // The login function acts as a facade for the different login endpoints
if (!credentials.username || !credentials.password) return; // Exception prevention
endpoint = "http://localhost:5000/api/login";
body = JSON.stringify({ username: credentials.username, password: credentials.password });
} else if (userType === "patient") {
if (!credentials.healthCareNumber) return; // Exception prevention
endpoint = "http://localhost:5000/api/patient_login";
body = JSON.stringify({ healthCareNumber: credentials.healthCareNumber });
}
The Exception Prevention Architecture Tactic for Availability is effectively applied in the login
function within the AuthProvider
component in the code snippet shown above. Before making a login request, the function checks for the required fields based on the userType
. For staff, it verifies that both username
and password
are provided, and for patients, it checks for healthCareNumber
. If any required fields are missing, the function exits early, preventing an exception from occurring due to incomplete data. This tactic is a good choice because it proactively avoids runtime errors that could disrupt the user experience or cause unexpected application behavior. By ensuring that all required information is present before proceeding with the API request, the code maintains stability and reliability, which is essential for providing a seamless and dependable user experience in applications where consistent availability is critical.