Function
safeParseBodyFromResponse
(
response: Response,
schema: z.Schema<T>
)
Source from the content-addressed store, hash-verified
| 49 | } |
| 50 | |
| 51 | export async function safeParseBodyFromResponse<T>( |
| 52 | response: Response, |
| 53 | schema: z.Schema<T> |
| 54 | ): Promise<z.SafeParseReturnType<unknown, T> | undefined> { |
| 55 | try { |
| 56 | const unknownJson = await response.json(); |
| 57 | |
| 58 | if (!unknownJson) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | const parsedJson = schema.safeParse(unknownJson); |
| 63 | |
| 64 | return parsedJson; |
| 65 | } catch (error) {} |
| 66 | } |
Tested by
no test coverage detected
Used in the wild real call sites across dependent graphs
searching dependent graphs…