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

fix: error when trying to save mock request file that doesn't exist #11

Merged
merged 2 commits into from
Apr 27, 2023

Conversation

nogw
Copy link
Contributor

@nogw nogw commented Apr 26, 2023

Description

As mentioned in issue #10, if the file "mock-requests.json" does not exist and you run the command "WRITE_MOCK=true yarn es scripts/test.ts", an error message will be shown, however, the file is created in any case

Changes

  • Add a simple check inside the try-catch block to determine if the error is due to the file not existing.

Related Issues

src/apiCache.ts Outdated
Comment on lines 52 to 55
if (err && err.code !== 'ENOENT') {
// eslint-disable-next-line
console.log({ err });
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this not is the best solution for your problem
Try to find the root cause

Copy link

@daniloab daniloab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @nogw thanks for the pull request

can you also add an improvement to create the mock JSON file when it does not exist before saving it?

Copy link

@fersilva16 fersilva16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if the file exists with fs.existsSync instead

Copy link

@edumaciel10 edumaciel10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the fs opening of writemock

@nogw
Copy link
Contributor Author

nogw commented Apr 27, 2023

done, using fs.existsSync and creating a empty file instead of ignoring the error

Copy link

@edumaciel10 edumaciel10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Good fix

@fersilva16 fersilva16 merged commit 44a3379 into main Apr 27, 2023
@fersilva16 fersilva16 deleted the fix/mock-requests-error-message branch April 27, 2023 14:39
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.

Error when trying to save mock request file that doesn't exist
4 participants