Skip to content

Commit

Permalink
fix: fix issues with failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
braposo committed Sep 10, 2019
1 parent f921e19 commit d9bd2f8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/utils/figma.ts
Expand Up @@ -64,6 +64,7 @@ const mapTypeToFunctionWithParams = {
};

const mapTypeToFunction = {
[RequestType.File]: file,
[RequestType.Comments]: comments,
[RequestType.Projects]: teamProjects,
[RequestType.ProjectFiles]: projectFiles,
Expand Down Expand Up @@ -114,15 +115,18 @@ async function getFigma<T extends FigmaResponse>({
console.log("fetching", key);

const fn: FigmaFunction =
params !== undefined
params === undefined
? mapTypeToFunction[requestType]
: mapTypeToFunctionWithParams[requestType];

try {
const { data } = await fn(id, { ...params });

// We just need to parse the response if it's for a file, otherwise we return the raw data
const processedData = "document" in data ? buildCustomFileReponse(data, id) : data;
const processedData =
"document" in data && requestType === RequestType.File
? buildCustomFileReponse(data, id)
: data;

// Only store data that doesn't change depending on the params
// We store it even if noCache is true so we can update the cache
Expand All @@ -132,7 +136,7 @@ async function getFigma<T extends FigmaResponse>({

return processedData as T;
} catch (e) {
throw new Error("Problem fetching data");
throw new Error(e);
}
}

Expand Down

0 comments on commit d9bd2f8

Please sign in to comment.