Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-211] Try parsing the response using JSON.parse after performing Typesense request #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nguyenkhavi
Copy link

@nguyenkhavi nguyenkhavi commented Jul 16, 2024

Change Summary

As @cungminh2710 already mentioned on this pull request, typesense-js will use the Axios fetch adapter in the case of Edge Runtime like Cloudflare. The Axios fetch adapter returns a string instead of a parsed object in the response body.
I added some lines of code to try parsing the response using JSON.parse after performing Typesense request:

  async _adaptAndPerformTypesenseRequest(instantsearchRequests) {
    const requestAdapter = new SearchRequestAdapter(instantsearchRequests, this.typesenseClient, this.configuration);
    const typesenseResponse = await requestAdapter.request();
    if (typeof typesenseResponse === "string") {
      try {
        return JSON.parse(typesenseResponse);
      } catch (error) {
        return typesenseResponse;
      }
    } else {
      return typesenseResponse;
    }
  }

Close GH-211

PR Checklist

@nguyenkhavi nguyenkhavi changed the title fix: try to JSON.parse the response after performing typesense request [GH-211] try to JSON.parse the response after performing typesense request Jul 16, 2024
@nguyenkhavi nguyenkhavi changed the title [GH-211] try to JSON.parse the response after performing typesense request [GH-211] Try to JSON.parse the response after performing typesense request Jul 16, 2024
@nguyenkhavi nguyenkhavi changed the title [GH-211] Try to JSON.parse the response after performing typesense request [GH-211] Try parsing the response using JSON.parse after performing Typesense request Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Receiving TypeError: Cannot read properties of undefined (reading 'map') on Edge Runtime (Cloudflare).
1 participant