Skip to content

Commit 99c2a6d

Browse files
committed
Throw Exceptions When Trying To Save A File
1 parent 0f76252 commit 99c2a6d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

IHP/FileStorage/ControllerFunctions.hs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ storeFileWithOptions fileInfo options = do
102102
let destPath :: Text = "static/" <> objectPath
103103
Directory.createDirectoryIfMissing True (cs $ "static/" <> directory)
104104

105-
fileInfo
106-
|> get #fileContent
107-
|> LBS.writeFile (cs destPath)
105+
trySaveFile <- Exception.try $ fileInfo |> get #fileContent |> LBS.writeFile (cs destPath)
106+
case trySaveFile of
107+
Left (Exception.SomeException e) -> throw e
108+
Right _ -> pure ()
108109

109110
let frameworkConfig = getFrameworkConfig ?context
110111
pure $ (get #baseUrl frameworkConfig) <> "/" <> objectPath
@@ -115,15 +116,18 @@ storeFileWithOptions fileInfo options = do
115116

116117
let contentType = cs (Wai.fileContentType fileInfo)
117118
contentDisposition <- (get #contentDisposition options) fileInfo
118-
runMinio connectInfo do
119+
trySaveFile <- runMinio connectInfo do
119120
let options :: PutObjectOptions = defaultPutObjectOptions { pooContentType = Just contentType, pooContentDisposition = contentDisposition }
120121
putObject bucket objectPath payload Nothing options
122+
case trySaveFile of
123+
Left e -> throw e
124+
Right _ -> pure ()
121125

122126
pure $ baseUrl <> objectPath
123127

124128
pure StoredFile { path = objectPath, url }
125129

126-
-- | Fetchs an url and uploads it to the storage.
130+
-- | Fetches an url and uploads it to the storage.
127131
--
128132
-- The stored file has the content type provided by @Content-Type@ header of the downloaded file.
129133
--

0 commit comments

Comments
 (0)