|
| 1 | +/* |
| 2 | + * Source++, the open-source live coding platform. |
| 3 | + * Copyright (C) 2022 CodeBrig, Inc. |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Affero General Public License as published |
| 7 | + * by the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Affero General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Affero General Public License |
| 16 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | +package spp.protocol.util |
| 19 | + |
| 20 | +import io.vertx.serviceproxy.ServiceException |
| 21 | +import spp.protocol.service.error.LiveInstrumentException |
| 22 | + |
| 23 | +object ServiceExceptionConverter { |
| 24 | + |
| 25 | + fun fromEventBusException(exception: String): ServiceException { |
| 26 | + return if (exception.startsWith("EventBusException")) { |
| 27 | + var exceptionType = exception.substringAfter("EventBusException:") |
| 28 | + exceptionType = exceptionType.substringBefore("[") |
| 29 | + var exceptionParams = exception.substringAfter("[") |
| 30 | + exceptionParams = exceptionParams.substringBefore("]") |
| 31 | + val exceptionMessage = exception.substringAfter("]: ").trim { it <= ' ' } |
| 32 | + if (LiveInstrumentException::class.java.simpleName == exceptionType) { |
| 33 | + LiveInstrumentException( |
| 34 | + LiveInstrumentException.ErrorType.valueOf(exceptionParams), |
| 35 | + exceptionMessage |
| 36 | + ).toEventBusException() |
| 37 | + } else { |
| 38 | + throw UnsupportedOperationException(exceptionType) |
| 39 | + } |
| 40 | + } else { |
| 41 | + throw IllegalArgumentException(exception) |
| 42 | + } |
| 43 | + } |
| 44 | +} |
0 commit comments