Skip to content

Inconsistent Configuration Fetching for SciCat Frontend #1728

@Ingvord

Description

@Ingvord

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

  1. Start the SciCat frontend application.
  2. 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.
  3. 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions