progressFn: (id, working) => {
store.dispatch(progressIndicatorActions.TOGGLE_WORKING({ id, working }));
},
- errorFn: (id, error) => {
- console.error("Backend error:", error);
- store.dispatch(snackbarActions.OPEN_SNACKBAR({
- message: `${error.errors
- ? error.errors[0]
- : error.message}`,
- kind: SnackbarKind.ERROR,
- hideDuration: 8000})
- );
+ errorFn: (id, error, showSnackBar) => {
+ if (showSnackBar) {
+ console.error("Backend error:", error);
+ store.dispatch(snackbarActions.OPEN_SNACKBAR({
+ message: `${error.errors
+ ? error.errors[0]
+ : error.message}`,
+ kind: SnackbarKind.ERROR,
+ hideDuration: 8000})
+ );
+ }
}
});
const store = configureStore(history, services);
const service = this.getService(extractUuidObjectType(startUuid));
if (service) {
try {
- const resource = await service.get(startUuid);
+ const resource = await service.get(startUuid, false);
if (startUuid === endUuid) {
return [resource];
} else {
} catch (e) {
return [];
}
- } else {
- return [];
}
+ return [];
}
private getService = (objectType?: string) => {
// SPDX-License-Identifier: AGPL-3.0
export type ProgressFn = (id: string, working: boolean) => void;
-export type ErrorFn = (id: string, error: any) => void;
+export type ErrorFn = (id: string, error: any, showSnackBar?: boolean) => void;
export interface ApiActions {
progressFn: ProgressFn;
}
}
- static defaultResponse<R>(promise: AxiosPromise<R>, actions: ApiActions, mapKeys = true): Promise<R> {
+ static defaultResponse<R>(promise: AxiosPromise<R>, actions: ApiActions, mapKeys = true, showErrors = true): Promise<R> {
const reqId = uuid();
actions.progressFn(reqId, true);
return promise
.catch(({ response }) => {
actions.progressFn(reqId, false);
const errors = CommonService.mapResponseKeys(response) as Errors;
- actions.errorFn(reqId, errors);
+ actions.errorFn(reqId, errors, showErrors);
throw errors;
});
}
);
}
- get(uuid: string) {
+ get(uuid: string, showErrors?: boolean) {
return CommonService.defaultResponse(
this.serverApi
.get<T>(this.resourceType + '/' + uuid),
- this.actions
+ this.actions,
+ true, // mapKeys
+ showErrors
);
}