-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
169 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
HttpInterceptorFn, | ||
HttpRequest, | ||
HttpHandlerFn, | ||
HttpErrorResponse, | ||
} from '@angular/common/http'; | ||
import { retry, catchError } from 'rxjs/operators'; | ||
import { Observable, throwError } from 'rxjs'; | ||
import { RollbarService } from './rollbar.service'; | ||
import { MessageService } from 'primeng/api'; | ||
import { inject } from '@angular/core'; | ||
|
||
export const httpErrorInterceptor: HttpInterceptorFn = ( | ||
req: HttpRequest<any>, | ||
next: HttpHandlerFn, | ||
): Observable<any> => { | ||
const rollbar = inject(RollbarService); | ||
const messageService = inject(MessageService); | ||
|
||
return next(req).pipe( | ||
retry(1), | ||
catchError((error: HttpErrorResponse) => { | ||
let errorMessage = ''; | ||
let errorSummary = ''; | ||
let errorDetail = ''; | ||
let tmpError = ''; | ||
|
||
if (error.error instanceof ErrorEvent) { | ||
// Client-side error | ||
errorDetail = `Error: ${error.error.message}`; | ||
errorSummary = 'Error'; | ||
} else { | ||
// Server-side error | ||
errorSummary = `Error Code: ${error.status}`; | ||
tmpError = `Message: ${error.message}`; | ||
const tmpSlashArray = tmpError.split('/'); | ||
if (tmpSlashArray.length > 0) { | ||
// Extract the last part of the error message | ||
const tmpString = tmpSlashArray[tmpSlashArray.length - 1]; | ||
const tmpSpaceArray: string[] = tmpString.split(' '); | ||
const finalString = tmpSpaceArray[0].slice(0, -1); | ||
if (tmpSpaceArray.length > 0) { | ||
tmpError = `Message: Gene ${finalString} not found!`; | ||
} | ||
} | ||
errorDetail = tmpError; | ||
} | ||
errorMessage += '\n' + errorSummary; | ||
|
||
// Displays error message on screen | ||
messageService.clear(); | ||
messageService.add({ | ||
severity: 'warn', | ||
sticky: true, | ||
summary: errorSummary, | ||
detail: errorDetail, | ||
life: 3000, | ||
}); | ||
|
||
setTimeout(() => { | ||
messageService.clear(); | ||
}, 3000); | ||
|
||
// Send the error message to Rollbar | ||
rollbar.error(error); | ||
|
||
return throwError(() => ({ errorSummary, errorMessage })); | ||
}), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,14 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { InjectionToken } from '@angular/core'; | ||
import Rollbar from 'rollbar'; | ||
import { ConfigService } from '@sagebionetworks/agora/config'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class RollbarService { | ||
private rollbarConfig = { | ||
accessToken: '', | ||
captureUncaught: true, | ||
captureUnhandledRejections: true, | ||
}; | ||
const rollbarConfig = { | ||
accessToken: 'e788198867474855a996485580b08d03', | ||
captureUncaught: true, | ||
captureUnhandledRejections: true, | ||
}; | ||
|
||
constructor(private configService: ConfigService) { | ||
this.rollbarConfig.accessToken = configService.config.rollbarToken; | ||
} | ||
|
||
getInstance() { | ||
return new Rollbar(this.rollbarConfig); | ||
} | ||
export function rollbarFactory() { | ||
return new Rollbar(rollbarConfig); | ||
} | ||
|
||
export const RollbarService = new InjectionToken<Rollbar>('rollbar'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.