-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathConfiguration.hs
More file actions
41 lines (35 loc) · 1.25 KB
/
Configuration.hs
File metadata and controls
41 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{-# LANGUAGE RankNTypes #-}
module Aws.Lambda.Runtime.Configuration
( DispatcherOptions (..),
defaultDispatcherOptions,
ErrorLogger,
flushOutput
)
where
import Aws.Lambda.Runtime.APIGateway.Types (ApiGatewayDispatcherOptions (..))
import Data.Text (Text)
import Data.Text.IO (hPutStrLn)
import Aws.Lambda.Runtime.Context
import Aws.Lambda.Runtime.Error
import System.IO (stderr, hFlush, stdout)
type ErrorLogger = forall context. Context context -> ErrorType -> Text -> IO ()
defaultErrorLogger :: ErrorLogger
defaultErrorLogger Context {awsRequestId=requestId} errorType message = do
hPutStrLn stderr $ requestId <> "\t"
<> "ERROR" <> "\t"
<> toReadableType errorType <> "\t"
<> message
flushOutput
-- | Options that the dispatcher generator expects
data DispatcherOptions = DispatcherOptions
{ apiGatewayDispatcherOptions :: ApiGatewayDispatcherOptions,
errorLogger :: ErrorLogger
}
defaultDispatcherOptions :: DispatcherOptions
defaultDispatcherOptions =
DispatcherOptions (ApiGatewayDispatcherOptions True) defaultErrorLogger
-- | Flush standard output ('stdout') and standard error output ('stderr') handlers
flushOutput :: IO ()
flushOutput = do
hFlush stdout
hFlush stderr