{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.StepFunctions.SendTaskFailure
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Used by activity workers and task states using the
-- <https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-wait-token callback>
-- pattern to report that the task identified by the @taskToken@ failed.
module Amazonka.StepFunctions.SendTaskFailure
  ( -- * Creating a Request
    SendTaskFailure (..),
    newSendTaskFailure,

    -- * Request Lenses
    sendTaskFailure_error,
    sendTaskFailure_cause,
    sendTaskFailure_taskToken,

    -- * Destructuring the Response
    SendTaskFailureResponse (..),
    newSendTaskFailureResponse,

    -- * Response Lenses
    sendTaskFailureResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.StepFunctions.Types

-- | /See:/ 'newSendTaskFailure' smart constructor.
data SendTaskFailure = SendTaskFailure'
  { -- | The error code of the failure.
    SendTaskFailure -> Maybe (Sensitive Text)
error :: Prelude.Maybe (Core.Sensitive Prelude.Text),
    -- | A more detailed explanation of the cause of the failure.
    SendTaskFailure -> Maybe (Sensitive Text)
cause :: Prelude.Maybe (Core.Sensitive Prelude.Text),
    -- | The token that represents this task. Task tokens are generated by Step
    -- Functions when tasks are assigned to a worker, or in the
    -- <https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html context object>
    -- when a workflow enters a task state. See
    -- GetActivityTaskOutput$taskToken.
    SendTaskFailure -> Text
taskToken :: Prelude.Text
  }
  deriving (SendTaskFailure -> SendTaskFailure -> Bool
(SendTaskFailure -> SendTaskFailure -> Bool)
-> (SendTaskFailure -> SendTaskFailure -> Bool)
-> Eq SendTaskFailure
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SendTaskFailure -> SendTaskFailure -> Bool
$c/= :: SendTaskFailure -> SendTaskFailure -> Bool
== :: SendTaskFailure -> SendTaskFailure -> Bool
$c== :: SendTaskFailure -> SendTaskFailure -> Bool
Prelude.Eq, Int -> SendTaskFailure -> ShowS
[SendTaskFailure] -> ShowS
SendTaskFailure -> String
(Int -> SendTaskFailure -> ShowS)
-> (SendTaskFailure -> String)
-> ([SendTaskFailure] -> ShowS)
-> Show SendTaskFailure
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SendTaskFailure] -> ShowS
$cshowList :: [SendTaskFailure] -> ShowS
show :: SendTaskFailure -> String
$cshow :: SendTaskFailure -> String
showsPrec :: Int -> SendTaskFailure -> ShowS
$cshowsPrec :: Int -> SendTaskFailure -> ShowS
Prelude.Show, (forall x. SendTaskFailure -> Rep SendTaskFailure x)
-> (forall x. Rep SendTaskFailure x -> SendTaskFailure)
-> Generic SendTaskFailure
forall x. Rep SendTaskFailure x -> SendTaskFailure
forall x. SendTaskFailure -> Rep SendTaskFailure x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendTaskFailure x -> SendTaskFailure
$cfrom :: forall x. SendTaskFailure -> Rep SendTaskFailure x
Prelude.Generic)

-- |
-- Create a value of 'SendTaskFailure' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'error', 'sendTaskFailure_error' - The error code of the failure.
--
-- 'cause', 'sendTaskFailure_cause' - A more detailed explanation of the cause of the failure.
--
-- 'taskToken', 'sendTaskFailure_taskToken' - The token that represents this task. Task tokens are generated by Step
-- Functions when tasks are assigned to a worker, or in the
-- <https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html context object>
-- when a workflow enters a task state. See
-- GetActivityTaskOutput$taskToken.
newSendTaskFailure ::
  -- | 'taskToken'
  Prelude.Text ->
  SendTaskFailure
newSendTaskFailure :: Text -> SendTaskFailure
newSendTaskFailure Text
pTaskToken_ =
  SendTaskFailure' :: Maybe (Sensitive Text)
-> Maybe (Sensitive Text) -> Text -> SendTaskFailure
SendTaskFailure'
    { $sel:error:SendTaskFailure' :: Maybe (Sensitive Text)
error = Maybe (Sensitive Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:cause:SendTaskFailure' :: Maybe (Sensitive Text)
cause = Maybe (Sensitive Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:taskToken:SendTaskFailure' :: Text
taskToken = Text
pTaskToken_
    }

-- | The error code of the failure.
sendTaskFailure_error :: Lens.Lens' SendTaskFailure (Prelude.Maybe Prelude.Text)
sendTaskFailure_error :: (Maybe Text -> f (Maybe Text))
-> SendTaskFailure -> f SendTaskFailure
sendTaskFailure_error = (SendTaskFailure -> Maybe (Sensitive Text))
-> (SendTaskFailure -> Maybe (Sensitive Text) -> SendTaskFailure)
-> Lens
     SendTaskFailure
     SendTaskFailure
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendTaskFailure' {Maybe (Sensitive Text)
error :: Maybe (Sensitive Text)
$sel:error:SendTaskFailure' :: SendTaskFailure -> Maybe (Sensitive Text)
error} -> Maybe (Sensitive Text)
error) (\s :: SendTaskFailure
s@SendTaskFailure' {} Maybe (Sensitive Text)
a -> SendTaskFailure
s {$sel:error:SendTaskFailure' :: Maybe (Sensitive Text)
error = Maybe (Sensitive Text)
a} :: SendTaskFailure) ((Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
 -> SendTaskFailure -> f SendTaskFailure)
-> ((Maybe Text -> f (Maybe Text))
    -> Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
-> (Maybe Text -> f (Maybe Text))
-> SendTaskFailure
-> f SendTaskFailure
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (Sensitive Text) (Sensitive Text) Text Text
-> Iso
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
     (Maybe Text)
     (Maybe Text)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso (Sensitive Text) (Sensitive Text) Text Text
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | A more detailed explanation of the cause of the failure.
sendTaskFailure_cause :: Lens.Lens' SendTaskFailure (Prelude.Maybe Prelude.Text)
sendTaskFailure_cause :: (Maybe Text -> f (Maybe Text))
-> SendTaskFailure -> f SendTaskFailure
sendTaskFailure_cause = (SendTaskFailure -> Maybe (Sensitive Text))
-> (SendTaskFailure -> Maybe (Sensitive Text) -> SendTaskFailure)
-> Lens
     SendTaskFailure
     SendTaskFailure
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendTaskFailure' {Maybe (Sensitive Text)
cause :: Maybe (Sensitive Text)
$sel:cause:SendTaskFailure' :: SendTaskFailure -> Maybe (Sensitive Text)
cause} -> Maybe (Sensitive Text)
cause) (\s :: SendTaskFailure
s@SendTaskFailure' {} Maybe (Sensitive Text)
a -> SendTaskFailure
s {$sel:cause:SendTaskFailure' :: Maybe (Sensitive Text)
cause = Maybe (Sensitive Text)
a} :: SendTaskFailure) ((Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
 -> SendTaskFailure -> f SendTaskFailure)
-> ((Maybe Text -> f (Maybe Text))
    -> Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
-> (Maybe Text -> f (Maybe Text))
-> SendTaskFailure
-> f SendTaskFailure
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (Sensitive Text) (Sensitive Text) Text Text
-> Iso
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
     (Maybe Text)
     (Maybe Text)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso (Sensitive Text) (Sensitive Text) Text Text
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | The token that represents this task. Task tokens are generated by Step
-- Functions when tasks are assigned to a worker, or in the
-- <https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html context object>
-- when a workflow enters a task state. See
-- GetActivityTaskOutput$taskToken.
sendTaskFailure_taskToken :: Lens.Lens' SendTaskFailure Prelude.Text
sendTaskFailure_taskToken :: (Text -> f Text) -> SendTaskFailure -> f SendTaskFailure
sendTaskFailure_taskToken = (SendTaskFailure -> Text)
-> (SendTaskFailure -> Text -> SendTaskFailure)
-> Lens SendTaskFailure SendTaskFailure Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendTaskFailure' {Text
taskToken :: Text
$sel:taskToken:SendTaskFailure' :: SendTaskFailure -> Text
taskToken} -> Text
taskToken) (\s :: SendTaskFailure
s@SendTaskFailure' {} Text
a -> SendTaskFailure
s {$sel:taskToken:SendTaskFailure' :: Text
taskToken = Text
a} :: SendTaskFailure)

instance Core.AWSRequest SendTaskFailure where
  type
    AWSResponse SendTaskFailure =
      SendTaskFailureResponse
  request :: SendTaskFailure -> Request SendTaskFailure
request = Service -> SendTaskFailure -> Request SendTaskFailure
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy SendTaskFailure
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SendTaskFailure)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse SendTaskFailure))
-> Logger
-> Service
-> Proxy SendTaskFailure
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SendTaskFailure)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> SendTaskFailureResponse
SendTaskFailureResponse'
            (Int -> SendTaskFailureResponse)
-> Either String Int -> Either String SendTaskFailureResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable SendTaskFailure

instance Prelude.NFData SendTaskFailure

instance Core.ToHeaders SendTaskFailure where
  toHeaders :: SendTaskFailure -> ResponseHeaders
toHeaders =
    ResponseHeaders -> SendTaskFailure -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSStepFunctions.SendTaskFailure" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON SendTaskFailure where
  toJSON :: SendTaskFailure -> Value
toJSON SendTaskFailure' {Maybe (Sensitive Text)
Text
taskToken :: Text
cause :: Maybe (Sensitive Text)
error :: Maybe (Sensitive Text)
$sel:taskToken:SendTaskFailure' :: SendTaskFailure -> Text
$sel:cause:SendTaskFailure' :: SendTaskFailure -> Maybe (Sensitive Text)
$sel:error:SendTaskFailure' :: SendTaskFailure -> Maybe (Sensitive Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"error" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Sensitive Text -> Pair) -> Maybe (Sensitive Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (Sensitive Text)
error,
            (Text
"cause" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Sensitive Text -> Pair) -> Maybe (Sensitive Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (Sensitive Text)
cause,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"taskToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
taskToken)
          ]
      )

instance Core.ToPath SendTaskFailure where
  toPath :: SendTaskFailure -> ByteString
toPath = ByteString -> SendTaskFailure -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery SendTaskFailure where
  toQuery :: SendTaskFailure -> QueryString
toQuery = QueryString -> SendTaskFailure -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newSendTaskFailureResponse' smart constructor.
data SendTaskFailureResponse = SendTaskFailureResponse'
  { -- | The response's http status code.
    SendTaskFailureResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (SendTaskFailureResponse -> SendTaskFailureResponse -> Bool
(SendTaskFailureResponse -> SendTaskFailureResponse -> Bool)
-> (SendTaskFailureResponse -> SendTaskFailureResponse -> Bool)
-> Eq SendTaskFailureResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SendTaskFailureResponse -> SendTaskFailureResponse -> Bool
$c/= :: SendTaskFailureResponse -> SendTaskFailureResponse -> Bool
== :: SendTaskFailureResponse -> SendTaskFailureResponse -> Bool
$c== :: SendTaskFailureResponse -> SendTaskFailureResponse -> Bool
Prelude.Eq, ReadPrec [SendTaskFailureResponse]
ReadPrec SendTaskFailureResponse
Int -> ReadS SendTaskFailureResponse
ReadS [SendTaskFailureResponse]
(Int -> ReadS SendTaskFailureResponse)
-> ReadS [SendTaskFailureResponse]
-> ReadPrec SendTaskFailureResponse
-> ReadPrec [SendTaskFailureResponse]
-> Read SendTaskFailureResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SendTaskFailureResponse]
$creadListPrec :: ReadPrec [SendTaskFailureResponse]
readPrec :: ReadPrec SendTaskFailureResponse
$creadPrec :: ReadPrec SendTaskFailureResponse
readList :: ReadS [SendTaskFailureResponse]
$creadList :: ReadS [SendTaskFailureResponse]
readsPrec :: Int -> ReadS SendTaskFailureResponse
$creadsPrec :: Int -> ReadS SendTaskFailureResponse
Prelude.Read, Int -> SendTaskFailureResponse -> ShowS
[SendTaskFailureResponse] -> ShowS
SendTaskFailureResponse -> String
(Int -> SendTaskFailureResponse -> ShowS)
-> (SendTaskFailureResponse -> String)
-> ([SendTaskFailureResponse] -> ShowS)
-> Show SendTaskFailureResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SendTaskFailureResponse] -> ShowS
$cshowList :: [SendTaskFailureResponse] -> ShowS
show :: SendTaskFailureResponse -> String
$cshow :: SendTaskFailureResponse -> String
showsPrec :: Int -> SendTaskFailureResponse -> ShowS
$cshowsPrec :: Int -> SendTaskFailureResponse -> ShowS
Prelude.Show, (forall x.
 SendTaskFailureResponse -> Rep SendTaskFailureResponse x)
-> (forall x.
    Rep SendTaskFailureResponse x -> SendTaskFailureResponse)
-> Generic SendTaskFailureResponse
forall x. Rep SendTaskFailureResponse x -> SendTaskFailureResponse
forall x. SendTaskFailureResponse -> Rep SendTaskFailureResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendTaskFailureResponse x -> SendTaskFailureResponse
$cfrom :: forall x. SendTaskFailureResponse -> Rep SendTaskFailureResponse x
Prelude.Generic)

-- |
-- Create a value of 'SendTaskFailureResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'httpStatus', 'sendTaskFailureResponse_httpStatus' - The response's http status code.
newSendTaskFailureResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  SendTaskFailureResponse
newSendTaskFailureResponse :: Int -> SendTaskFailureResponse
newSendTaskFailureResponse Int
pHttpStatus_ =
  SendTaskFailureResponse' :: Int -> SendTaskFailureResponse
SendTaskFailureResponse' {$sel:httpStatus:SendTaskFailureResponse' :: Int
httpStatus = Int
pHttpStatus_}

-- | The response's http status code.
sendTaskFailureResponse_httpStatus :: Lens.Lens' SendTaskFailureResponse Prelude.Int
sendTaskFailureResponse_httpStatus :: (Int -> f Int)
-> SendTaskFailureResponse -> f SendTaskFailureResponse
sendTaskFailureResponse_httpStatus = (SendTaskFailureResponse -> Int)
-> (SendTaskFailureResponse -> Int -> SendTaskFailureResponse)
-> Lens SendTaskFailureResponse SendTaskFailureResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendTaskFailureResponse' {Int
httpStatus :: Int
$sel:httpStatus:SendTaskFailureResponse' :: SendTaskFailureResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: SendTaskFailureResponse
s@SendTaskFailureResponse' {} Int
a -> SendTaskFailureResponse
s {$sel:httpStatus:SendTaskFailureResponse' :: Int
httpStatus = Int
a} :: SendTaskFailureResponse)

instance Prelude.NFData SendTaskFailureResponse