Skip to content

Commit 7003f2d

Browse files
committed
add Input is Too Long error based on ValidationError
1 parent 96bcbe7 commit 7003f2d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Sources/BedrockService.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ public struct BedrockService: Sendable {
223223
)
224224
}
225225
}
226+
} else if let validationError = error as? AWSBedrockRuntime.ValidationException {
227+
logger.trace("ValidationException while \(context)", metadata: ["error": "\(error)"])
228+
let message = validationError.properties.message ?? "Validation error occurred"
229+
if message.contains("Input is too long") {
230+
throw BedrockLibraryError.inputTooLong(message)
231+
} else {
232+
throw BedrockLibraryError.invalid(message)
233+
}
226234
} else {
227235
logger.trace("Error while \(context)", metadata: ["error": "\(error)"])
228236
throw error

Sources/BedrockServiceError.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public enum BedrockLibraryError: Error {
4141
case notSupported(String)
4242
case notFound(String)
4343
case authenticationFailed(String)
44+
case inputTooLong(String)
4445
case unknownError(String)
4546

4647
public var message: String {
@@ -86,6 +87,8 @@ public enum BedrockLibraryError: Error {
8687
return "Not found: \(message)"
8788
case .authenticationFailed(let message):
8889
return "Authentication failed: \(message)"
90+
case .inputTooLong(let message):
91+
return "Input too long: \(message)"
8992
case .unknownError(let message):
9093
return "Unknown error: \(message)"
9194
}

0 commit comments

Comments
 (0)