fun execute()

in notifications/core/src/main/kotlin/org/opensearch/notifications/core/client/DestinationSnsClient.kt [44:84]


    fun execute(destination: SnsDestination, message: MessageContent, referenceId: String): DestinationMessageResponse {
        val amazonSNS: AmazonSNS = snsClientFactory.createSnsClient(destination.region, destination.roleArn)
        return try {
            val result = sendMessage(amazonSNS, destination, message)
            DestinationMessageResponse(RestStatus.OK.status, "Success, message id: ${result.messageId}")
        } catch (exception: InvalidParameterException) {
            DestinationMessageResponse(RestStatus.BAD_REQUEST.status, getSnsExceptionText(exception))
        } catch (exception: InvalidParameterValueException) {
            DestinationMessageResponse(RestStatus.BAD_REQUEST.status, getSnsExceptionText(exception))
        } catch (exception: InternalErrorException) {
            DestinationMessageResponse(RestStatus.INTERNAL_SERVER_ERROR.status, getSnsExceptionText(exception))
        } catch (exception: NotFoundException) {
            DestinationMessageResponse(RestStatus.NOT_FOUND.status, getSnsExceptionText(exception))
        } catch (exception: EndpointDisabledException) {
            DestinationMessageResponse(RestStatus.LOCKED.status, getSnsExceptionText(exception))
        } catch (exception: PlatformApplicationDisabledException) {
            DestinationMessageResponse(RestStatus.SERVICE_UNAVAILABLE.status, getSnsExceptionText(exception))
        } catch (exception: AuthorizationErrorException) {
            DestinationMessageResponse(RestStatus.UNAUTHORIZED.status, getSnsExceptionText(exception))
        } catch (exception: KMSDisabledException) {
            DestinationMessageResponse(RestStatus.PRECONDITION_FAILED.status, getSnsExceptionText(exception))
        } catch (exception: KMSInvalidStateException) {
            DestinationMessageResponse(RestStatus.PRECONDITION_FAILED.status, getSnsExceptionText(exception))
        } catch (exception: KMSNotFoundException) {
            DestinationMessageResponse(RestStatus.PRECONDITION_FAILED.status, getSnsExceptionText(exception))
        } catch (exception: KMSOptInRequiredException) {
            DestinationMessageResponse(RestStatus.PRECONDITION_FAILED.status, getSnsExceptionText(exception))
        } catch (exception: KMSThrottlingException) {
            DestinationMessageResponse(RestStatus.TOO_MANY_REQUESTS.status, getSnsExceptionText(exception))
        } catch (exception: KMSAccessDeniedException) {
            DestinationMessageResponse(RestStatus.UNAUTHORIZED.status, getSnsExceptionText(exception))
        } catch (exception: InvalidSecurityException) {
            DestinationMessageResponse(RestStatus.UNAUTHORIZED.status, getSnsExceptionText(exception))
        } catch (exception: AmazonSNSException) {
            DestinationMessageResponse(RestStatus.FAILED_DEPENDENCY.status, getSnsExceptionText(exception))
        } catch (exception: AmazonServiceException) {
            DestinationMessageResponse(RestStatus.FAILED_DEPENDENCY.status, getServiceExceptionText(exception))
        } catch (exception: SdkBaseException) {
            DestinationMessageResponse(RestStatus.FAILED_DEPENDENCY.status, getSdkExceptionText(exception))
        }
    }