From 4ee8ec239613c46bc86f4af4639a0398e64853d2 Mon Sep 17 00:00:00 2001 From: ck-c8y Date: Sun, 26 Jan 2025 12:31:47 +0100 Subject: [PATCH] update service --- README.md | 5 ----- analytics-service/c8y_agent.py | 1 - analytics-service/flask_wrapper.py | 7 ++++++- analytics-ui/src/shared/repository.service.ts | 18 ++++++++++++++---- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index daa9576..675fb53 100644 --- a/README.md +++ b/README.md @@ -237,11 +237,6 @@ In order to check if an extension is deployed look for a relevant message in the The log file can be accessed: Administration> Ecosystem>Microservices>apama-ctrl-1c-4g>Logs -> **Note** -When a warning `Microservice: analytics-ext-service not subscribed. Please subscribe this service before using the analytics plugin!`appears please deploy the missing backend microservice. - -![Backend microservice missing](resources/images/missing-microsevice.png) - ------------------------------ These tools are provided as-is and without warranty or support. They do not constitute part of the Software AG product suite. Users are free to use, fork and modify them, subject to the license agreement. While Software AG welcomes contributions, we cannot guarantee to include every contribution in the master project. diff --git a/analytics-service/c8y_agent.py b/analytics-service/c8y_agent.py index 745ad67..52b8e34 100644 --- a/analytics-service/c8y_agent.py +++ b/analytics-service/c8y_agent.py @@ -1,6 +1,5 @@ import logging from sre_constants import CATEGORY -import requests from dotenv import load_dotenv from c8y_api.app import MultiTenantCumulocityApp from c8y_api.model import Binary, TenantOption diff --git a/analytics-service/flask_wrapper.py b/analytics-service/flask_wrapper.py index 5377709..8b233c8 100644 --- a/analytics-service/flask_wrapper.py +++ b/analytics-service/flask_wrapper.py @@ -424,6 +424,11 @@ def parse_boolean(value): return value.lower() == "true" return False - +def prepare_header(request): + headers = dict(request.headers) + if "authorization" in request.cookies: + headers["Authorization"] = f"Bearer {request.cookies['authorization']}" + return headers + if __name__ == "__main__": app.run(host="0.0.0.0", port=80, debug=False) diff --git a/analytics-ui/src/shared/repository.service.ts b/analytics-ui/src/shared/repository.service.ts index ebef944..8661277 100644 --- a/analytics-ui/src/shared/repository.service.ts +++ b/analytics-ui/src/shared/repository.service.ts @@ -121,7 +121,7 @@ export class RepositoryService { throw error; } } - + private loadRepositories(): Observable { return from(this.fetchRepositoriesFromBackend()).pipe( catchError(error => { @@ -204,8 +204,18 @@ export class RepositoryService { ); if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + // Try to get the error message from the response body + try { + const errorData = await response.json(); + const errorMessage = errorData.message || errorData.error || JSON.stringify(errorData); + throw new Error(errorMessage); + } catch (parseError) { + // If we can't parse the JSON, fall back to text + const errorText = parseError.message; + throw new Error(errorText); + } } + return response.json(); } @@ -295,7 +305,7 @@ export class RepositoryService { private handleError(error: HttpErrorResponse): void { const message = error.status ? `Backend returned code ${error.status}: ${error.message}` - : `Network error: ${error.message}`; - this.alertService.danger('Repository error', message); + : error.message; + this.alertService.danger(message); } } \ No newline at end of file