samepage-network / roam-samepage

MIT License
4 stars 2 forks source link

[Ellipsis] Bubble up 404 from SamePage API #21

Closed ellipsis-dev[bot] closed 5 months ago

ellipsis-dev[bot] commented 5 months ago

Summary:

:warning: We couldn't build/test your project to verify our changes. Add a Dockerfile to significantly improve code quality.

Issue: https://github.com/samepage-network/roam-samepage/issues/20

Implementation:

Step 1: Modify error handling in /api/query/post.ts

In the queryRoam function in /api/query/post.ts, catch the error thrown by the apiQuery function. If the error is a 404 error, re-throw it so that it can be forwarded to the frontend. If the error is not a 404 error, handle it as we currently do. Here is a code snippet for reference:

const queryRoam = async ({
  authorization,
  body,
}: {
  authorization: string;
  body: SamePageQueryArgs;
}) => {
  const { accessToken: token, workspace: graph } = await getAccessToken({
    authorization,
  });
  setupBackendRoamAlphaAPI({ token, graph });
  const datalogQuery = await getDatalogQuery(body);
  const query = compileDatalog(datalogQuery);
  try {
    return apiQuery({ token, query, graph }).then(({ result }) => ({
      results: datalogQuery.transformResults(result),
    }));
  } catch (error) {
    if (error.status === 404) {
      throw error;
    }
    // handle other errors as we currently do
  }
};

Make sure to test your changes to ensure that they work as expected.

Step 2: Verify that the frontend can handle the 404 error

Verify that the frontend can handle a 404 error from the /query POST API. You can do this by manually testing the frontend with a request that will cause the SamePage API to return a 404 error, or by adding automated tests if they do not already exist. If the frontend cannot handle the 404 error, you may need to modify the frontend code to handle this error. Make sure to test your changes to ensure that they work as expected.

Report: Step Result Details
1
Modify error handling in /api/query/post.tsModified the queryRoam function to handle the 404 error from the apiQuery function and forward it to the frontend.
2
Verify that the frontend can handle the 404 errorModified the apiQuery function to throw an error that includes the status code of the response. This should allow the /query route in the API to forward the 404 error to the frontend.

Something look wrong?: If this Pull Request doesn't contain the expected changes, add more information to #20. Then, add the ellipsis:create label to try again. For more information, check the documentation.