15672: Delete comment out code
[arvados.git] / src / services / common-service / common-resource-service.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
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";
9
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',
15     UNKNOWN = 'Unknown',
16     NONE = 'None'
17 }
18
19 export class CommonResourceService<T extends Resource> extends CommonService<T> {
20    constructor(serverApi: AxiosInstance, resourceType: string, actions: ApiActions) {
21         super(serverApi, resourceType, actions);
22     }
23 }
24
25 export const getCommonResourceServiceError = (errorResponse: any) => {
26     if ('errors' in errorResponse && 'errorToken' in errorResponse) {
27         const error = errorResponse.errors.join('');
28         switch (true) {
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;
37             default:
38                 return CommonResourceServiceError.UNKNOWN;
39         }
40     }
41     return CommonResourceServiceError.NONE;
42 };
43
44