Skip to content

Commit

Permalink
🐛 Max Limit Fehlerhandling implementiert
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoKocevar committed Aug 31, 2023
1 parent 35d2899 commit 7ca1808
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
38 changes: 38 additions & 0 deletions frontend/src/mixins/requests/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,44 @@ export default class ErrorHandler extends Mixins(InformationListMixin) {
return error;
}

public handleResponseNotOk(showInInformationList: boolean, error: Response): Response {
if (!error.ok) {
if (error.type === "opaqueredirect") {
location.reload();
} else if (error.status === 403) {
const errorMessage = ErrorHandler.ERROR_MESSAGE_NOT_AUTHORIZED;
this.showErrorInformation(showInInformationList, errorMessage);
} else if (error.status === 503) {
// ResponseError vom Loadbalancer. D.h. das Gateway konnte nicht erreicht werden.
const errorMessage = ErrorHandler.ERROR_MESSAGE_GATEWAY;
this.showErrorInformation(showInInformationList, errorMessage);
} else if (error.status !== 500) {
// Das Backend reagiert mit einer fachlichen Fehlermeldung.
error.json().then((json: unknown) => {
const informationResponseDto: InformationResponseDto = InformationResponseDtoFromJSON(json);

if (showInInformationList) {
this.showInformationResponseDtoInInformationList(informationResponseDto);
} else {
// Show as Toast
const messages: string = _.join(informationResponseDto.messages, "; ");
const toastLevel: Levels = this.getToastLevel(informationResponseDto.type);
Toaster.toast(messages, toastLevel);
}
});
} else if (error.status === 500) {
// ResponseError vom Gateway. D.h. das Gateway aber nicht das Backend konnte erreicht werden.
const errorMessage = ErrorHandler.ERROR_MESSAGE_BACKEND;
this.showErrorInformation(showInInformationList, errorMessage);
} else {
// TypeError -> Der fetch-Request ist fehlgeschlagen.
const errorMessage = ErrorHandler.ERROR_MESSAGE_GATEWAY;
this.showErrorInformation(showInInformationList, errorMessage);
}
}
return error;
}

/**
* @param showInInformationList falls true. Andernfalls wird der Fehler als Toast gezeigt.
* @param errorMessage welche angezeigt werden soll.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ export default class StatusUebergangApiRequestMixin extends Mixins(ErrorHandler)
transition: TransitionDto,
abfrageId: string | undefined,
anmerkung: string | undefined
): Promise<boolean> {
): Promise<Response | void> {
const fetchUrl =
import.meta.env.VITE_VUE_APP_API_URL +
`/api/isi-backend-service/infrastruktur-abfrage/${abfrageId}/${transition.url}?anmerkung=${anmerkung}`;
return fetch(fetchUrl, RequestUtils.getPUTConfig())
.then((response) => response.ok)
.catch((error) => {
.then((response) => {
return response;
})
.catch((error: Error) => {
this.handleError(true, error);
return false;
});
}
}
24 changes: 15 additions & 9 deletions frontend/src/views/Abfrage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ import {
BaugebietDto,
BaurateDto,
InfrastrukturabfrageDto,
ResponseError,
StatusAbfrage,
TransitionDto,
} from "@/api/api-client/isi-backend";
Expand Down Expand Up @@ -532,17 +533,22 @@ export default class Abfrage extends Mixins(
}
const validationMessage: string | null = this.findFaultInInfrastrukturabfrageForSave(this.abfrage);
if (_.isNil(validationMessage)) {
const requestSuccessful = await this.statusUebergangRequest(transition, this.abfrageId, this.anmerkung);
if (requestSuccessful) {
if (!(transition.url === "in-bearbeitung-setzen")) {
this.returnToUebersicht(toastMessage, Levels.SUCCESS);
const response = await this.statusUebergangRequest(transition, this.abfrageId, this.anmerkung);
if (response instanceof Response) {
if (response.ok) {
if (!(transition.url === "in-bearbeitung-setzen")) {
this.returnToUebersicht(toastMessage, Levels.SUCCESS);
} else {
this.setSelectedAbfrageInStore();
this.getTransitions(this.abfrageId, true).then((response) => {
this.possbileTransitions = response;
});
}
this.selectAbfrage();
} else {
this.setSelectedAbfrageInStore();
this.getTransitions(this.abfrageId, true).then((response) => {
this.possbileTransitions = response;
});
this.anmerkung = "";
this.handleResponseNotOk(true, response);
}
this.selectAbfrage();
}
} else {
this.showWarningInInformationList(validationMessage);
Expand Down

0 comments on commit 7ca1808

Please sign in to comment.