2 * Copyright © 2020 IBM, Bell Canada.
3 * Modifications Copyright © 2019-2020 AT&T Intellectual Property.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.error.catalog.core
20 interface ErrorCatalogExceptionFluent<T> {
21 fun code(code: Int): T
22 fun domain(domain: String): T
23 fun action(action: String): T
24 fun http(type: String): T
25 fun grpc(type: String): T
26 fun payloadMessage(message: String): T
27 fun addErrorPayloadMessage(message: String): T
28 fun addSubError(errorMessage: ErrorMessage): T
31 open class ErrorCatalogException : RuntimeException {
33 var domain: String = ""
34 var name: String = ErrorCatalogCodes.GENERIC_FAILURE
35 var action: String = ""
36 var errorPayload: ErrorPayload? = null
37 var protocol: String = ""
38 var errorPayloadMessages: MutableList<String>? = null
40 val messageSeparator = "${System.lineSeparator()} -> "
42 constructor(message: String, cause: Throwable) : super(message, cause)
43 constructor(message: String) : super(message)
44 constructor(cause: Throwable) : super(cause)
45 constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause)
47 constructor(code: Int, cause: Throwable) : super(cause) {
51 constructor(code: Int, message: String) : super(message) {
55 constructor(code: Int, message: String, cause: Throwable) : super(message, cause) {
59 constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) :
60 super(String.format(message, *args), cause) {
64 open fun <T : ErrorCatalogException> updateCode(code: Int): T {
69 open fun <T : ErrorCatalogException> updateDomain(domain: String): T {
74 open fun <T : ErrorCatalogException> updateAction(action: String): T {
79 fun <T : ErrorCatalogException> updateHttp(type: String): T {
80 this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_HTTP
81 this.code = HttpErrorCodes.code(type)
85 fun <T : ErrorCatalogException> updateGrpc(type: String): T {
86 this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_GRPC
87 this.code = GrpcErrorCodes.code(type)
91 fun <T : ErrorCatalogException> updatePayloadMessage(message: String): T {
92 if (this.errorPayloadMessages == null) this.errorPayloadMessages = arrayListOf()
93 this.errorPayloadMessages!!.add(message)
97 fun <T : ErrorCatalogException> updateErrorPayloadMessage(message: String): T {
98 if (errorPayload == null) {
99 errorPayload = ErrorPayload()
101 errorPayload!!.message = "${errorPayload!!.message} $messageSeparator $message"
105 fun <T : ErrorCatalogException> updateSubError(errorMessage: ErrorMessage): T {
106 if (errorPayload == null) {
107 errorPayload = ErrorPayload()
109 errorPayload!!.subErrors.add(errorMessage)