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

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

-- |
-- Module      : Amazonka.CloudFront.Types.CustomErrorResponse
-- 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)
module Amazonka.CloudFront.Types.CustomErrorResponse where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A complex type that controls:
--
-- -   Whether CloudFront replaces HTTP status codes in the 4xx and 5xx
--     range with custom error messages before returning the response to
--     the viewer.
--
-- -   How long CloudFront caches HTTP status codes in the 4xx and 5xx
--     range.
--
-- For more information about custom error pages, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/custom-error-pages.html Customizing Error Responses>
-- in the /Amazon CloudFront Developer Guide/.
--
-- /See:/ 'newCustomErrorResponse' smart constructor.
data CustomErrorResponse = CustomErrorResponse'
  { -- | The path to the custom error page that you want CloudFront to return to
    -- a viewer when your origin returns the HTTP status code specified by
    -- @ErrorCode@, for example, @\/4xx-errors\/403-forbidden.html@. If you
    -- want to store your objects and your custom error pages in different
    -- locations, your distribution must include a cache behavior for which the
    -- following is true:
    --
    -- -   The value of @PathPattern@ matches the path to your custom error
    --     messages. For example, suppose you saved custom error pages for 4xx
    --     errors in an Amazon S3 bucket in a directory named @\/4xx-errors@.
    --     Your distribution must include a cache behavior for which the path
    --     pattern routes requests for your custom error pages to that
    --     location, for example, @\/4xx-errors\/*@.
    --
    -- -   The value of @TargetOriginId@ specifies the value of the @ID@
    --     element for the origin that contains your custom error pages.
    --
    -- If you specify a value for @ResponsePagePath@, you must also specify a
    -- value for @ResponseCode@.
    --
    -- We recommend that you store custom error pages in an Amazon S3 bucket.
    -- If you store custom error pages on an HTTP server and the server starts
    -- to return 5xx errors, CloudFront can\'t get the files that you want to
    -- return to viewers because the origin server is unavailable.
    CustomErrorResponse -> Maybe Text
responsePagePath :: Prelude.Maybe Prelude.Text,
    -- | The HTTP status code that you want CloudFront to return to the viewer
    -- along with the custom error page. There are a variety of reasons that
    -- you might want CloudFront to return a status code different from the
    -- status code that your origin returned to CloudFront, for example:
    --
    -- -   Some Internet devices (some firewalls and corporate proxies, for
    --     example) intercept HTTP 4xx and 5xx and prevent the response from
    --     being returned to the viewer. If you substitute @200@, the response
    --     typically won\'t be intercepted.
    --
    -- -   If you don\'t care about distinguishing among different client
    --     errors or server errors, you can specify @400@ or @500@ as the
    --     @ResponseCode@ for all 4xx or 5xx errors.
    --
    -- -   You might want to return a @200@ status code (OK) and static website
    --     so your customers don\'t know that your website is down.
    --
    -- If you specify a value for @ResponseCode@, you must also specify a value
    -- for @ResponsePagePath@.
    CustomErrorResponse -> Maybe Text
responseCode :: Prelude.Maybe Prelude.Text,
    -- | The minimum amount of time, in seconds, that you want CloudFront to
    -- cache the HTTP status code specified in @ErrorCode@. When this time
    -- period has elapsed, CloudFront queries your origin to see whether the
    -- problem that caused the error has been resolved and the requested object
    -- is now available.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/custom-error-pages.html Customizing Error Responses>
    -- in the /Amazon CloudFront Developer Guide/.
    CustomErrorResponse -> Maybe Integer
errorCachingMinTTL :: Prelude.Maybe Prelude.Integer,
    -- | The HTTP status code for which you want to specify a custom error page
    -- and\/or a caching duration.
    CustomErrorResponse -> Int
errorCode :: Prelude.Int
  }
  deriving (CustomErrorResponse -> CustomErrorResponse -> Bool
(CustomErrorResponse -> CustomErrorResponse -> Bool)
-> (CustomErrorResponse -> CustomErrorResponse -> Bool)
-> Eq CustomErrorResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomErrorResponse -> CustomErrorResponse -> Bool
$c/= :: CustomErrorResponse -> CustomErrorResponse -> Bool
== :: CustomErrorResponse -> CustomErrorResponse -> Bool
$c== :: CustomErrorResponse -> CustomErrorResponse -> Bool
Prelude.Eq, ReadPrec [CustomErrorResponse]
ReadPrec CustomErrorResponse
Int -> ReadS CustomErrorResponse
ReadS [CustomErrorResponse]
(Int -> ReadS CustomErrorResponse)
-> ReadS [CustomErrorResponse]
-> ReadPrec CustomErrorResponse
-> ReadPrec [CustomErrorResponse]
-> Read CustomErrorResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomErrorResponse]
$creadListPrec :: ReadPrec [CustomErrorResponse]
readPrec :: ReadPrec CustomErrorResponse
$creadPrec :: ReadPrec CustomErrorResponse
readList :: ReadS [CustomErrorResponse]
$creadList :: ReadS [CustomErrorResponse]
readsPrec :: Int -> ReadS CustomErrorResponse
$creadsPrec :: Int -> ReadS CustomErrorResponse
Prelude.Read, Int -> CustomErrorResponse -> ShowS
[CustomErrorResponse] -> ShowS
CustomErrorResponse -> String
(Int -> CustomErrorResponse -> ShowS)
-> (CustomErrorResponse -> String)
-> ([CustomErrorResponse] -> ShowS)
-> Show CustomErrorResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomErrorResponse] -> ShowS
$cshowList :: [CustomErrorResponse] -> ShowS
show :: CustomErrorResponse -> String
$cshow :: CustomErrorResponse -> String
showsPrec :: Int -> CustomErrorResponse -> ShowS
$cshowsPrec :: Int -> CustomErrorResponse -> ShowS
Prelude.Show, (forall x. CustomErrorResponse -> Rep CustomErrorResponse x)
-> (forall x. Rep CustomErrorResponse x -> CustomErrorResponse)
-> Generic CustomErrorResponse
forall x. Rep CustomErrorResponse x -> CustomErrorResponse
forall x. CustomErrorResponse -> Rep CustomErrorResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomErrorResponse x -> CustomErrorResponse
$cfrom :: forall x. CustomErrorResponse -> Rep CustomErrorResponse x
Prelude.Generic)

-- |
-- Create a value of 'CustomErrorResponse' 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:
--
-- 'responsePagePath', 'customErrorResponse_responsePagePath' - The path to the custom error page that you want CloudFront to return to
-- a viewer when your origin returns the HTTP status code specified by
-- @ErrorCode@, for example, @\/4xx-errors\/403-forbidden.html@. If you
-- want to store your objects and your custom error pages in different
-- locations, your distribution must include a cache behavior for which the
-- following is true:
--
-- -   The value of @PathPattern@ matches the path to your custom error
--     messages. For example, suppose you saved custom error pages for 4xx
--     errors in an Amazon S3 bucket in a directory named @\/4xx-errors@.
--     Your distribution must include a cache behavior for which the path
--     pattern routes requests for your custom error pages to that
--     location, for example, @\/4xx-errors\/*@.
--
-- -   The value of @TargetOriginId@ specifies the value of the @ID@
--     element for the origin that contains your custom error pages.
--
-- If you specify a value for @ResponsePagePath@, you must also specify a
-- value for @ResponseCode@.
--
-- We recommend that you store custom error pages in an Amazon S3 bucket.
-- If you store custom error pages on an HTTP server and the server starts
-- to return 5xx errors, CloudFront can\'t get the files that you want to
-- return to viewers because the origin server is unavailable.
--
-- 'responseCode', 'customErrorResponse_responseCode' - The HTTP status code that you want CloudFront to return to the viewer
-- along with the custom error page. There are a variety of reasons that
-- you might want CloudFront to return a status code different from the
-- status code that your origin returned to CloudFront, for example:
--
-- -   Some Internet devices (some firewalls and corporate proxies, for
--     example) intercept HTTP 4xx and 5xx and prevent the response from
--     being returned to the viewer. If you substitute @200@, the response
--     typically won\'t be intercepted.
--
-- -   If you don\'t care about distinguishing among different client
--     errors or server errors, you can specify @400@ or @500@ as the
--     @ResponseCode@ for all 4xx or 5xx errors.
--
-- -   You might want to return a @200@ status code (OK) and static website
--     so your customers don\'t know that your website is down.
--
-- If you specify a value for @ResponseCode@, you must also specify a value
-- for @ResponsePagePath@.
--
-- 'errorCachingMinTTL', 'customErrorResponse_errorCachingMinTTL' - The minimum amount of time, in seconds, that you want CloudFront to
-- cache the HTTP status code specified in @ErrorCode@. When this time
-- period has elapsed, CloudFront queries your origin to see whether the
-- problem that caused the error has been resolved and the requested object
-- is now available.
--
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/custom-error-pages.html Customizing Error Responses>
-- in the /Amazon CloudFront Developer Guide/.
--
-- 'errorCode', 'customErrorResponse_errorCode' - The HTTP status code for which you want to specify a custom error page
-- and\/or a caching duration.
newCustomErrorResponse ::
  -- | 'errorCode'
  Prelude.Int ->
  CustomErrorResponse
newCustomErrorResponse :: Int -> CustomErrorResponse
newCustomErrorResponse Int
pErrorCode_ =
  CustomErrorResponse' :: Maybe Text
-> Maybe Text -> Maybe Integer -> Int -> CustomErrorResponse
CustomErrorResponse'
    { $sel:responsePagePath:CustomErrorResponse' :: Maybe Text
responsePagePath =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:responseCode:CustomErrorResponse' :: Maybe Text
responseCode = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:errorCachingMinTTL:CustomErrorResponse' :: Maybe Integer
errorCachingMinTTL = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:errorCode:CustomErrorResponse' :: Int
errorCode = Int
pErrorCode_
    }

-- | The path to the custom error page that you want CloudFront to return to
-- a viewer when your origin returns the HTTP status code specified by
-- @ErrorCode@, for example, @\/4xx-errors\/403-forbidden.html@. If you
-- want to store your objects and your custom error pages in different
-- locations, your distribution must include a cache behavior for which the
-- following is true:
--
-- -   The value of @PathPattern@ matches the path to your custom error
--     messages. For example, suppose you saved custom error pages for 4xx
--     errors in an Amazon S3 bucket in a directory named @\/4xx-errors@.
--     Your distribution must include a cache behavior for which the path
--     pattern routes requests for your custom error pages to that
--     location, for example, @\/4xx-errors\/*@.
--
-- -   The value of @TargetOriginId@ specifies the value of the @ID@
--     element for the origin that contains your custom error pages.
--
-- If you specify a value for @ResponsePagePath@, you must also specify a
-- value for @ResponseCode@.
--
-- We recommend that you store custom error pages in an Amazon S3 bucket.
-- If you store custom error pages on an HTTP server and the server starts
-- to return 5xx errors, CloudFront can\'t get the files that you want to
-- return to viewers because the origin server is unavailable.
customErrorResponse_responsePagePath :: Lens.Lens' CustomErrorResponse (Prelude.Maybe Prelude.Text)
customErrorResponse_responsePagePath :: (Maybe Text -> f (Maybe Text))
-> CustomErrorResponse -> f CustomErrorResponse
customErrorResponse_responsePagePath = (CustomErrorResponse -> Maybe Text)
-> (CustomErrorResponse -> Maybe Text -> CustomErrorResponse)
-> Lens
     CustomErrorResponse CustomErrorResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomErrorResponse' {Maybe Text
responsePagePath :: Maybe Text
$sel:responsePagePath:CustomErrorResponse' :: CustomErrorResponse -> Maybe Text
responsePagePath} -> Maybe Text
responsePagePath) (\s :: CustomErrorResponse
s@CustomErrorResponse' {} Maybe Text
a -> CustomErrorResponse
s {$sel:responsePagePath:CustomErrorResponse' :: Maybe Text
responsePagePath = Maybe Text
a} :: CustomErrorResponse)

-- | The HTTP status code that you want CloudFront to return to the viewer
-- along with the custom error page. There are a variety of reasons that
-- you might want CloudFront to return a status code different from the
-- status code that your origin returned to CloudFront, for example:
--
-- -   Some Internet devices (some firewalls and corporate proxies, for
--     example) intercept HTTP 4xx and 5xx and prevent the response from
--     being returned to the viewer. If you substitute @200@, the response
--     typically won\'t be intercepted.
--
-- -   If you don\'t care about distinguishing among different client
--     errors or server errors, you can specify @400@ or @500@ as the
--     @ResponseCode@ for all 4xx or 5xx errors.
--
-- -   You might want to return a @200@ status code (OK) and static website
--     so your customers don\'t know that your website is down.
--
-- If you specify a value for @ResponseCode@, you must also specify a value
-- for @ResponsePagePath@.
customErrorResponse_responseCode :: Lens.Lens' CustomErrorResponse (Prelude.Maybe Prelude.Text)
customErrorResponse_responseCode :: (Maybe Text -> f (Maybe Text))
-> CustomErrorResponse -> f CustomErrorResponse
customErrorResponse_responseCode = (CustomErrorResponse -> Maybe Text)
-> (CustomErrorResponse -> Maybe Text -> CustomErrorResponse)
-> Lens
     CustomErrorResponse CustomErrorResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomErrorResponse' {Maybe Text
responseCode :: Maybe Text
$sel:responseCode:CustomErrorResponse' :: CustomErrorResponse -> Maybe Text
responseCode} -> Maybe Text
responseCode) (\s :: CustomErrorResponse
s@CustomErrorResponse' {} Maybe Text
a -> CustomErrorResponse
s {$sel:responseCode:CustomErrorResponse' :: Maybe Text
responseCode = Maybe Text
a} :: CustomErrorResponse)

-- | The minimum amount of time, in seconds, that you want CloudFront to
-- cache the HTTP status code specified in @ErrorCode@. When this time
-- period has elapsed, CloudFront queries your origin to see whether the
-- problem that caused the error has been resolved and the requested object
-- is now available.
--
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/custom-error-pages.html Customizing Error Responses>
-- in the /Amazon CloudFront Developer Guide/.
customErrorResponse_errorCachingMinTTL :: Lens.Lens' CustomErrorResponse (Prelude.Maybe Prelude.Integer)
customErrorResponse_errorCachingMinTTL :: (Maybe Integer -> f (Maybe Integer))
-> CustomErrorResponse -> f CustomErrorResponse
customErrorResponse_errorCachingMinTTL = (CustomErrorResponse -> Maybe Integer)
-> (CustomErrorResponse -> Maybe Integer -> CustomErrorResponse)
-> Lens
     CustomErrorResponse
     CustomErrorResponse
     (Maybe Integer)
     (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomErrorResponse' {Maybe Integer
errorCachingMinTTL :: Maybe Integer
$sel:errorCachingMinTTL:CustomErrorResponse' :: CustomErrorResponse -> Maybe Integer
errorCachingMinTTL} -> Maybe Integer
errorCachingMinTTL) (\s :: CustomErrorResponse
s@CustomErrorResponse' {} Maybe Integer
a -> CustomErrorResponse
s {$sel:errorCachingMinTTL:CustomErrorResponse' :: Maybe Integer
errorCachingMinTTL = Maybe Integer
a} :: CustomErrorResponse)

-- | The HTTP status code for which you want to specify a custom error page
-- and\/or a caching duration.
customErrorResponse_errorCode :: Lens.Lens' CustomErrorResponse Prelude.Int
customErrorResponse_errorCode :: (Int -> f Int) -> CustomErrorResponse -> f CustomErrorResponse
customErrorResponse_errorCode = (CustomErrorResponse -> Int)
-> (CustomErrorResponse -> Int -> CustomErrorResponse)
-> Lens CustomErrorResponse CustomErrorResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomErrorResponse' {Int
errorCode :: Int
$sel:errorCode:CustomErrorResponse' :: CustomErrorResponse -> Int
errorCode} -> Int
errorCode) (\s :: CustomErrorResponse
s@CustomErrorResponse' {} Int
a -> CustomErrorResponse
s {$sel:errorCode:CustomErrorResponse' :: Int
errorCode = Int
a} :: CustomErrorResponse)

instance Core.FromXML CustomErrorResponse where
  parseXML :: [Node] -> Either String CustomErrorResponse
parseXML [Node]
x =
    Maybe Text
-> Maybe Text -> Maybe Integer -> Int -> CustomErrorResponse
CustomErrorResponse'
      (Maybe Text
 -> Maybe Text -> Maybe Integer -> Int -> CustomErrorResponse)
-> Either String (Maybe Text)
-> Either
     String (Maybe Text -> Maybe Integer -> Int -> CustomErrorResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"ResponsePagePath")
      Either
  String (Maybe Text -> Maybe Integer -> Int -> CustomErrorResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Integer -> Int -> CustomErrorResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"ResponseCode")
      Either String (Maybe Integer -> Int -> CustomErrorResponse)
-> Either String (Maybe Integer)
-> Either String (Int -> CustomErrorResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Integer)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"ErrorCachingMinTTL")
      Either String (Int -> CustomErrorResponse)
-> Either String Int -> Either String CustomErrorResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Int
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"ErrorCode")

instance Prelude.Hashable CustomErrorResponse

instance Prelude.NFData CustomErrorResponse

instance Core.ToXML CustomErrorResponse where
  toXML :: CustomErrorResponse -> XML
toXML CustomErrorResponse' {Int
Maybe Integer
Maybe Text
errorCode :: Int
errorCachingMinTTL :: Maybe Integer
responseCode :: Maybe Text
responsePagePath :: Maybe Text
$sel:errorCode:CustomErrorResponse' :: CustomErrorResponse -> Int
$sel:errorCachingMinTTL:CustomErrorResponse' :: CustomErrorResponse -> Maybe Integer
$sel:responseCode:CustomErrorResponse' :: CustomErrorResponse -> Maybe Text
$sel:responsePagePath:CustomErrorResponse' :: CustomErrorResponse -> Maybe Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"ResponsePagePath" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
responsePagePath,
        Name
"ResponseCode" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
responseCode,
        Name
"ErrorCachingMinTTL" Name -> Maybe Integer -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Integer
errorCachingMinTTL,
        Name
"ErrorCode" Name -> Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Int
errorCode
      ]