1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { AxiosInstance } from "axios";
6 import { Resource } from "src/models/resource";
7 import { ApiActions } from "~/services/api/api-actions";
8 import { CommonService } from "~/services/common-service/common-service";
10 export enum CommonResourceServiceError {
11 UNIQUE_NAME_VIOLATION = 'UniqueNameViolation',
12 OWNERSHIP_CYCLE = 'OwnershipCycle',
13 MODIFYING_CONTAINER_REQUEST_FINAL_STATE = 'ModifyingContainerRequestFinalState',
14 NAME_HAS_ALREADY_BEEN_TAKEN = 'NameHasAlreadyBeenTaken',
19 export class CommonResourceService<T extends Resource> extends CommonService<T> {
20 constructor(serverApi: AxiosInstance, resourceType: string, actions: ApiActions) {
21 super(serverApi, resourceType, actions);
25 export const getCommonResourceServiceError = (errorResponse: any) => {
26 if ('errors' in errorResponse && 'errorToken' in errorResponse) {
27 const error = errorResponse.errors.join('');
29 case /UniqueViolation/.test(error):
30 return CommonResourceServiceError.UNIQUE_NAME_VIOLATION;
31 case /ownership cycle/.test(error):
32 return CommonResourceServiceError.OWNERSHIP_CYCLE;
33 case /Mounts cannot be modified in state 'Final'/.test(error):
34 return CommonResourceServiceError.MODIFYING_CONTAINER_REQUEST_FINAL_STATE;
35 case /Name has already been taken/.test(error):
36 return CommonResourceServiceError.NAME_HAS_ALREADY_BEEN_TAKEN;
38 return CommonResourceServiceError.UNKNOWN;
41 return CommonResourceServiceError.NONE;