-
Notifications
You must be signed in to change notification settings - Fork 34
Description
Issue Name
Inconsistent Configuration Fetching for SciCat Frontend
Summary
Currently, there is an inconsistency in how the SciCat frontend fetches its configuration. The frontend supports fetching configuration both locally (from a static file) and remotely (from the backend), leading to unnecessary complexity and potential confusion.
Steps to Reproduce
- Start the SciCat frontend application.
- Observe how the configuration is fetched: First, it attempts to fetch configuration from the backend at
/backend/api/v3/admin/config
.
If the backend configuration is unavailable, it falls back to fetching local configuration from/scicat/assets/config.json
. - Analyze the code behavior and handling in case of errors or missing configurations.
Current Behaviour
The frontend uses a nested try-catch structure to manage configuration fetching, which is an anti-pattern for flow control.
This approach introduces confusion and tightly couples frontend behavior to backend configuration, violating separation of concerns.
try {
const config = await this.http
.get("/backend/api/v3/admin/config")
.pipe(timeout(2000))
.toPromise();
this.appConfig = Object.assign({}, this.appConfig, config);
} catch (err) {
console.log("No config available in backend, trying with local config.");
try {
const config = await this.http.get("/scicat/assets/config.json").toPromise();
this.appConfig = Object.assign({}, this.appConfig, config);
} catch (err) {
console.error("No config provided.");
}
}
Expected Behaviour
The backend should not be responsible for providing frontend configurations.
The frontend configuration should be purely local to the frontend to avoid unnecessary dependencies.
Error handling should avoid the use of try-catch
for flow control and instead use a cleaner and more modular approach.
Extra Details
Refactor the configuration fetching logic to remove the backend dependency for frontend configuration.
Ensure error handling is clean and adheres to best practices.
If remote configuration is unavoidable, establish a clear distinction between backend and frontend configuration responsibilities.