(num: number, shorten: boolean = false)
| 162 | } |
| 163 | |
| 164 | export function isValidUUID(str: string): boolean { |
| 165 | const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; |
| 166 | return uuidRegex.test(str); |
| 167 | } |
| 168 | |
| 169 | export async function parseResultJsonWithZodSchema<T>( |
| 170 | response: Response, |
| 171 | schema: ZodType<T> |
| 172 | ): Promise<T> { |
| 173 | if (!response.ok) { |
| 174 | let errorMessage = `Failed to fetch data: ${response.statusText}`; |
| 175 | |
| 176 | try { |
| 177 | const errorData = await response.json(); |
| 178 | |
| 179 | // Check for API error message |
| 180 | if ( |
| 181 | errorData && |
| 182 | typeof errorData === 'object' && |
| 183 | 'error' in errorData && |
| 184 | typeof errorData.error === 'string' |
| 185 | ) { |
| 186 | errorMessage = errorData.error; |
| 187 | } |
no outgoing calls
no test coverage detected