ChemPal Documentation - v1.6.0
    Preparing search index...
    • Type guard to validate if a Response object contains JSON content. Checks both the Content-Type header and ensures it's a valid Response object.

      Parameters

      • response: unknown

        The Response object to validate

      Returns asserts response is Response

      Type predicate indicating if the response contains JSON content

      // Valid JSON response
      const jsonResponse = new Response('{"data": "test"}', {
      headers: { 'Content-Type': 'application/json' }
      });
      assertJsonResponse(jsonResponse);
      export function assertJsonResponse(response: unknown): asserts response is Response {
      if (!isJsonResponse(response)) {
      throw new TypeError('assertJsonResponse| Invalid JSON response', { cause: response });
      }
      }