Enabling Code Formatter
[ccsdk/cds.git] / ms / error-catalog / core / src / main / kotlin / org / onap / ccsdk / cds / error / catalog / core / ErrorCodes.kt
1 /*
2  * Copyright © 2018-2019 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.cds.error.catalog.core
18
19 object ErrorCatalogCodes {
20
21     const val GENERIC_FAILURE = "GENERIC_FAILURE"
22     const val GENERIC_PROCESS_FAILURE = "GENERIC_PROCESS_FAILURE"
23     const val INVALID_FILE_EXTENSION = "INVALID_FILE_EXTENSION"
24     const val RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND"
25     const val RESOURCE_PATH_MISSING = "RESOURCE_PATH_MISSING"
26     const val RESOURCE_WRITING_FAIL = "RESOURCE_WRITING_FAIL"
27     const val IO_FILE_INTERRUPT = "IO_FILE_INTERRUPT"
28     const val INVALID_REQUEST_FORMAT = "INVALID_REQUEST_FORMAT"
29     const val UNAUTHORIZED_REQUEST = "UNAUTHORIZED_REQUEST"
30     const val REQUEST_NOT_FOUND = "REQUEST_NOT_FOUND"
31     const val CONFLICT_ADDING_RESOURCE = "CONFLICT_ADDING_RESOURCE"
32     const val DUPLICATE_DATA = "DUPLICATE_DATA"
33 }
34
35 object HttpErrorCodes {
36
37     private val store: MutableMap<String, Int> = mutableMapOf()
38
39     init {
40         store[ErrorCatalogCodes.GENERIC_FAILURE] = 500
41         store[ErrorCatalogCodes.GENERIC_PROCESS_FAILURE] = 500
42         store[ErrorCatalogCodes.INVALID_FILE_EXTENSION] = 415
43         store[ErrorCatalogCodes.RESOURCE_NOT_FOUND] = 404
44         store[ErrorCatalogCodes.RESOURCE_PATH_MISSING] = 503
45         store[ErrorCatalogCodes.RESOURCE_WRITING_FAIL] = 503
46         store[ErrorCatalogCodes.IO_FILE_INTERRUPT] = 503
47         store[ErrorCatalogCodes.INVALID_REQUEST_FORMAT] = 400
48         store[ErrorCatalogCodes.UNAUTHORIZED_REQUEST] = 401
49         store[ErrorCatalogCodes.REQUEST_NOT_FOUND] = 404
50         store[ErrorCatalogCodes.CONFLICT_ADDING_RESOURCE] = 409
51         store[ErrorCatalogCodes.DUPLICATE_DATA] = 409
52     }
53
54     fun register(type: String, code: Int) {
55         store[type] = code
56     }
57
58     fun code(type: String): Int {
59         return store[type] ?: store[ErrorCatalogCodes.GENERIC_FAILURE]!!
60     }
61 }
62
63 object GrpcErrorCodes {
64
65     private val store: MutableMap<String, Int> = mutableMapOf()
66
67     init {
68         store[ErrorCatalogCodes.GENERIC_FAILURE] = 2
69         store[ErrorCatalogCodes.GENERIC_PROCESS_FAILURE] = 2
70         store[ErrorCatalogCodes.INVALID_FILE_EXTENSION] = 3
71         store[ErrorCatalogCodes.RESOURCE_NOT_FOUND] = 5
72         store[ErrorCatalogCodes.RESOURCE_PATH_MISSING] = 3
73         store[ErrorCatalogCodes.RESOURCE_WRITING_FAIL] = 9
74         store[ErrorCatalogCodes.IO_FILE_INTERRUPT] = 3
75         store[ErrorCatalogCodes.INVALID_REQUEST_FORMAT] = 3
76         store[ErrorCatalogCodes.UNAUTHORIZED_REQUEST] = 16
77         store[ErrorCatalogCodes.REQUEST_NOT_FOUND] = 8
78         store[ErrorCatalogCodes.CONFLICT_ADDING_RESOURCE] = 10
79         store[ErrorCatalogCodes.DUPLICATE_DATA] = 11
80     }
81
82     fun register(type: String, code: Int) {
83         store[type] = code
84     }
85
86     fun code(type: String): Int {
87         return store[type] ?: store[ErrorCatalogCodes.GENERIC_FAILURE]!!
88     }
89 }