(error: unknown, bucketName: string)
| 175 | }; |
| 176 | |
| 177 | const getS3ConnectionErrorMessage = (error: unknown, bucketName: string) => { |
| 178 | if (!(error instanceof Error)) return "Failed to connect to S3"; |
| 179 | |
| 180 | if (error.name === "AbortError" || error.name === "TimeoutError") { |
| 181 | return "Connection timed out after 5 seconds. Please check the endpoint URL and your network connection."; |
| 182 | } |
| 183 | |
| 184 | if (error.name === "NoSuchBucket") { |
| 185 | return `Bucket '${bucketName}' does not exist`; |
| 186 | } |
| 187 | |
| 188 | if (error.name === "NetworkingError") { |
| 189 | return "Network error. Please check the endpoint URL and your network connection."; |
| 190 | } |
| 191 | |
| 192 | if (error.name === "InvalidAccessKeyId") { |
| 193 | return "Invalid Access Key ID"; |
| 194 | } |
| 195 | |
| 196 | if (error.name === "SignatureDoesNotMatch") { |
| 197 | return "Invalid Secret Access Key"; |
| 198 | } |
| 199 | |
| 200 | if (error.name === "AccessDenied") { |
| 201 | return "Access denied. Please check your credentials and bucket permissions."; |
| 202 | } |
| 203 | |
| 204 | if (getS3ErrorMetadata(error)?.httpStatusCode === 301) { |
| 205 | return "Received 301 redirect. This usually means the endpoint URL is incorrect or the bucket is in a different region."; |
| 206 | } |
| 207 | |
| 208 | return "Failed to connect to S3"; |
| 209 | }; |
| 210 | |
| 211 | const driveHasStoredData = async ( |
| 212 | drive: typeof storageIntegrations.$inferSelect, |
no test coverage detected