Skip to content

Commit

Permalink
handle errors when repo url is incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Nov 28, 2023
1 parent d60a527 commit a8e9b13
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
8 changes: 4 additions & 4 deletions analytics-ui/src/sample/list/sample.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ export class SampleGridComponent implements OnInit {
ignoreBackdropClick: true,
});

modalRef.content.closeSubject.subscribe(async (conf) => {
console.log("Configuration after edit:", conf);
if (conf) {
const response = await this.repositoryService.saveRepositories();
modalRef.content.closeSubject.subscribe(async (repositories) => {
console.log("Repositories after edit:", repositories);
if (repositories) {
const response = await this.repositoryService.saveRepositories(repositories);
this.alertService.success(
gettext(`Updated repositories successfully‚`)
);
Expand Down
24 changes: 20 additions & 4 deletions analytics-ui/src/shared/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {

import { TranslateService } from "@ngx-translate/core";
import * as _ from "lodash";
import { BehaviorSubject, Subscription } from "rxjs";
import { BehaviorSubject, EMPTY, Subscription, throwError } from "rxjs";
import {
CEP_Block,
CEP_Extension,
Expand All @@ -37,8 +37,8 @@ import {
ENDPOINT_EXTENSION,
Repository,
} from "./analytics.model";
import { filter, map, pairwise } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
import { catchError, filter, map, pairwise } from "rxjs/operators";
import { HttpClient, HttpErrorResponse } from "@angular/common/http";
import { RepositoryService } from "../sample/editor/repository.service";

@Injectable({ providedIn: "root" })
Expand Down Expand Up @@ -192,12 +192,28 @@ export class AnalyticsService {
b.repositoryName = rep.name;
});
return name;
})
}),
catchError(this.handleError),
)
.toPromise();
return result;
}

private handleError(error: HttpErrorResponse) {
if (error.status === 0) {
// A client-side or network error occurred. Handle it accordingly.
console.error('An error occurred. Ignoring repository:', error.error);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong.
console.error(
`Backend returned code ${error.status}. Ignoring repository. Error body was: `, error.error);
}
// Return an observable with a user-facing error message.
//return throwError(() => new Error('Something bad happened; please try again later.'));
return EMPTY
}

async getBlock_Sample_Content(name: string): Promise<string> {
const sampleUrl = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/${REPO_SAMPLES_NAME}/contents/${REPO_SAMPLES_PATH}/${name}`;
const result: any = this.githubFetchClient
Expand Down

0 comments on commit a8e9b13

Please sign in to comment.