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