2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2018 - 2020 IBM, Bell Canada.
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.cds.controllerblueprints.core
20 import org.onap.ccsdk.error.catalog.core.ErrorCatalogException
21 import org.onap.ccsdk.error.catalog.core.ErrorCatalogExceptionFluent
22 import org.onap.ccsdk.error.catalog.core.ErrorMessage
27 * @author Brinda Santh
29 open class BluePrintProcessorException : ErrorCatalogException, ErrorCatalogExceptionFluent<BluePrintProcessorException> {
31 constructor(message: String, cause: Throwable) : super(message, cause)
32 constructor(message: String) : super(message)
33 constructor(cause: Throwable) : super(cause)
34 constructor(cause: Throwable, message: String, vararg args: Any?) : super(cause, message, args)
35 constructor(code: Int, cause: Throwable) : super(code, cause)
36 constructor(code: Int, message: String) : super(code, message)
37 constructor(code: Int, message: String, cause: Throwable) : super(code, message, cause)
39 override fun code(code: Int): BluePrintProcessorException {
40 return this.updateCode(code)
43 override fun domain(domain: String): BluePrintProcessorException {
44 return this.updateDomain(domain)
47 override fun action(action: String): BluePrintProcessorException {
48 return this.updateAction(action)
51 override fun http(type: String): BluePrintProcessorException {
52 return this.updateHttp(type)
55 override fun grpc(type: String): BluePrintProcessorException {
56 return this.updateGrpc(type)
59 override fun payloadMessage(message: String): BluePrintProcessorException {
60 return this.updatePayloadMessage(message)
63 override fun addErrorPayloadMessage(message: String): BluePrintProcessorException {
64 return this.updateErrorPayloadMessage(message)
67 override fun addSubError(errorMessage: ErrorMessage): BluePrintProcessorException {
68 return this.updateSubError(errorMessage)
72 class BluePrintRetryException : RuntimeException {
73 constructor(message: String, cause: Throwable) : super(message, cause)
74 constructor(message: String) : super(message)
75 constructor(cause: Throwable) : super(cause)
76 constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause)
79 /** Extension Functions */
81 fun processorException(message: String): BluePrintProcessorException {
82 return BluePrintProcessorException(message)
85 fun processorException(code: Int, message: String): BluePrintProcessorException {
86 return processorException(message).code(code)
89 fun httpProcessorException(type: String, message: String): BluePrintProcessorException {
90 return processorException(message).http(type)
93 fun grpcProcessorException(type: String, message: String): BluePrintProcessorException {
94 return processorException(message).grpc(type)
97 fun httpProcessorException(type: String, domain: String, message: String): BluePrintProcessorException {
98 val bluePrintProcessorException = processorException(message).http(type)
99 return bluePrintProcessorException.addDomainAndErrorMessage(domain, message)
102 fun grpcProcessorException(type: String, domain: String, message: String): BluePrintProcessorException {
103 val bluePrintProcessorException = processorException(message).grpc(type)
104 return bluePrintProcessorException.addDomainAndErrorMessage(domain, message)
107 fun httpProcessorException(type: String, domain: String, message: String, cause: Throwable):
108 BluePrintProcessorException {
109 val bluePrintProcessorException = processorException(message).http(type)
110 return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, cause)
113 fun grpcProcessorException(type: String, domain: String, message: String, cause: Throwable):
114 BluePrintProcessorException {
115 val bluePrintProcessorException = processorException(message).grpc(type)
116 return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, cause)
119 fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String, cause: Throwable):
120 BluePrintProcessorException {
121 return this.addDomainAndErrorMessage(domain, message, cause).domain(domain)
122 .addErrorPayloadMessage(message)
123 .payloadMessage(message)
126 fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String): BluePrintProcessorException {
127 return this.addDomainAndErrorMessage(domain, message).domain(domain)
128 .addErrorPayloadMessage(message)
129 .payloadMessage(message)
132 private fun BluePrintProcessorException.addDomainAndErrorMessage(
135 cause: Throwable = Throwable()
136 ): BluePrintProcessorException {
137 return this.addSubError(ErrorMessage(domain, message, cause.message ?: "")).domain(domain)