Skip to content

Commit

Permalink
#1061: add 404 message when loading non existing task (#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanStrehlerCGI authored Dec 11, 2023
1 parent 5b256a3 commit f4ac831
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {AxiosError} from "axios";


export interface ApiCallError {
readonly message: string
readonly status?: number
}

export const defaultApiErrorHandler = (err: AxiosError): ApiCallError => {
const error: ApiCallError = {
status: err.response?.status,
message: (err.response?.data as any)?.error || "unknown error"
};
return error;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {ApiConfig} from "../ApiConfig";
import {PageOfTasks, TaskApiFactory, TasksApiFactory, TaskWithSchema} from "@muenchen/digiwf-task-api-internal";
import {AxiosError} from "axios";
import {TaskVariables} from "../../middleware/tasks/tasksModels";
import {defaultApiErrorHandler} from "../defaultErrorHandler";

export const callGetTasksFromTaskService = (page: number, size: number, query?: string, tag?: string, followUp?: string, sort?: string): Promise<PageOfTasks> => {
// follow-up: YYYY-MM-dd: e.g. 2023-04-17
Expand Down Expand Up @@ -42,7 +43,7 @@ export const callGetTaskDetailsFromTaskService = (taskId: string): Promise<TaskW
const cfg = ApiConfig.getTasklistAxiosConfig(FetchUtils.getGETConfig());
return TaskApiFactory(cfg).getTaskWithSchemaByTaskId(taskId)
.then((res) => Promise.resolve(res.data))
.catch((err: AxiosError) => Promise.reject(FetchUtils.defaultCatchHandler(err, "Die Aufgabe konnte nicht geladen werden.")));
.catch((err: AxiosError) => Promise.reject(defaultApiErrorHandler(err)));
};

export const callCancelTaskInTaskService = (taskId: string): Promise<void> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ import {
import {computed, ref, Ref} from "vue";
import {Page} from "../commonModels";
import {HumanTask, HumanTaskDetails, TaskVariables} from "./tasksModels";
import {
mapTaskDetailsFromTaskService,
mapTaskFromTaskService,
} from "./taskMapper";
import {mapTaskDetailsFromTaskService, mapTaskFromTaskService,} from "./taskMapper";
import {useStore} from "../../hooks/store";
import axios, {AxiosError} from "axios";
import {dateToIsoDateTime, getCurrentDate} from "../../utils/time";
import router from "../../router";
import {queryClient} from "../queryClient";
Expand All @@ -33,6 +29,7 @@ import {
isInFinishedProcesses
} from "./mutatedTaskFilter";
import {nullToUndefined} from "../../utils/dataTransformations";
import {ApiCallError} from "../../api/defaultErrorHandler";

const extractTag = (tag: Ref<string | undefined>): string | undefined => {
const currentValue = tag.value;
Expand Down Expand Up @@ -222,8 +219,8 @@ export const loadTask = (taskId: string): Promise<LoadTaskResult> => {
});
});

}).catch((error: Error | AxiosError) => {
if (axios.isAxiosError(error) && (error as AxiosError).status === 404) {
}).catch((error: ApiCallError) => {
if (error.status === 404) {
return Promise.resolve({
error: "Die Aufgabe oder der zugehörige Vorgang wurden bereits abgeschlossen. Die Aufgabe kann daher nicht mehr angezeigt oder bearbeitet werden."
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package de.muenchen.oss.digiwf.task.service.application.port.out.polyflow;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
* Signals that the task with given id is not available.
*/
@ResponseStatus(HttpStatus.NOT_FOUND)
public class TaskNotFoundException extends RuntimeException {
/**
* Creates new exception with corresponding error message.
Expand Down

0 comments on commit f4ac831

Please sign in to comment.