(errorMessage?: string)
| 12 | * @returns string object name or null |
| 13 | */ |
| 14 | export function alreadyExistsError(errorMessage?: string) { |
| 15 | if (!errorMessage) { |
| 16 | return null; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * This regex takes a string and extracts a substring in single or double quotation marks |
| 21 | * only if the sentence ends with "already exists". |
| 22 | */ |
| 23 | const strInsideQuotesMatch = /['"]([^'"]*)['"][\s\S]*already exists$/g.exec( |
| 24 | errorMessage, |
| 25 | ); |
| 26 | |
| 27 | if (strInsideQuotesMatch && strInsideQuotesMatch.length > 1) { |
| 28 | return strInsideQuotesMatch[1]; |
| 29 | } |
| 30 | |
| 31 | return null; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Looks for "cannot create multiple replicas named" error messages and returns the object name |
no test coverage detected