Skip to content

Commit

Permalink
persist frontend error during provider connection into the backend ta…
Browse files Browse the repository at this point in the history
…ble for easier debugging.
  • Loading branch information
AnalogJ committed Jan 21, 2024
1 parent fe8c485 commit e2fa945
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {EventBusService} from '../../services/event-bus.service';
import {SourceState} from '../../models/fasten/source-state';
import {PatientAccessBrand} from '../../models/patient-access-brands';
import {environment} from '../../../environments/environment';
import {BackgroundJobSyncData} from '../../models/fasten/background-job';

@Component({
selector: 'app-medical-sources-connected',
Expand Down Expand Up @@ -232,10 +233,33 @@ export class MedicalSourcesConnectedComponent implements OnInit {

const toastNotification = new ToastNotification()
toastNotification.type = ToastType.Error
toastNotification.message = `An error occurred while accessing external data source: '${this.extractErrorFromResponse(err)}'`
toastNotification.message = `An error occurred while initializing external data source connection: '${this.extractErrorFromResponse(err)}'`
toastNotification.autohide = false
this.toastService.show(toastNotification)
console.error(err)

let errData = new BackgroundJobSyncData()
errData.source_id = expectedSourceStateInfo.reconnect_source_id
errData.brand_id = expectedSourceStateInfo.brand_id
errData.checkpoint_data = {
//don't copy confidential data to the error data
state: expectedSourceStateInfo.state,
endpoint_id: expectedSourceStateInfo.endpoint_id,
portal_id: expectedSourceStateInfo.portal_id,
brand_id: expectedSourceStateInfo.brand_id,
reconnect_source_id: expectedSourceStateInfo.reconnect_source_id,
code_challenge_method: expectedSourceStateInfo.code_challenge_method,
redirect_uri: expectedSourceStateInfo.redirect_uri,
}
errData.error_data = {
summary: toastNotification.message,
error: JSON.stringify(err),
stack: err.stack
}

//attempt to persist this error to the background job table. ignore any errors that occur during this process.
this.fastenApi.createBackgroundJobError(errData).subscribe(console.log)

})
}

Expand Down
8 changes: 8 additions & 0 deletions frontend/src/app/models/fasten/background-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ export class BackgroundJob {
retries: number
schedule?: string
}

export class BackgroundJobSyncData {
source_id?: string
brand_id: string
checkpoint_data?: {[key:string]:string}
error_data?: {[key:string]:string}

}
13 changes: 12 additions & 1 deletion frontend/src/app/services/fasten-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {DashboardConfig} from '../models/widget/dashboard-config';
import {DashboardWidgetQuery} from '../models/widget/dashboard-widget-query';
import {ResourceGraphResponse} from '../models/fasten/resource-graph-response';
import { fetchEventSource } from '@microsoft/fetch-event-source';
import {BackgroundJob} from '../models/fasten/background-job';
import {BackgroundJob, BackgroundJobSyncData} from '../models/fasten/background-job';
import {SupportRequest} from '../models/fasten/support-request';
import {
List
Expand Down Expand Up @@ -335,6 +335,17 @@ export class FastenApiService {
);
}

//this method will persist client side errors in the database for later review & easier debugging. Primarily used for source/provider connection errors
createBackgroundJobError(errorData: BackgroundJobSyncData){
return this._httpClient.post<any>(`${GetEndpointAbsolutePath(globalThis.location, environment.fasten_api_endpoint_base)}/secure/jobs/error`, errorData)
.pipe(
map((response: ResponseWrapper) => {
console.log("RESPONSE", response)
return response.data
})
);
}


supportRequest(request: SupportRequest): Observable<any> {
return this._httpClient.post<any>(`${GetEndpointAbsolutePath(globalThis.location, environment.fasten_api_endpoint_base)}/support/request`, request)
Expand Down

0 comments on commit e2fa945

Please sign in to comment.