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

Improved Error Handling for Queries, Simplified Logic, and Formatted README #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

spabolu
Copy link

@spabolu spabolu commented Mar 23, 2023

In this pull request, I have implemented several enhancements to the existing codebase, focusing on error handling for queries, simplifying logic, and reformatting the README page for better readability and understanding. Although I have limited experience with TypeScript, I have tried my best to contribute positively to the project. I also plan to potentially add a feature for retrieving an array of reviews in the future once I learn more TypeScript. Any feedback or suggestions for further improvements are highly appreciated.

List of Changes:
Error Handling: Added comprehensive error handling for queries to ensure the application can handle unexpected issues gracefully. This includes checking for malformed queries, unreachable data sources, and other possible errors that could arise during execution.

Simplified Logic: Reviewed and refactored the existing logic in the codebase to make it more efficient, readable, and maintainable. This will help other contributors to easily understand and build upon the code in the future.

README Reformatting: Restructured the README page to make it more user-friendly and informative. This includes adding clear headings and sections, improving the formatting of code snippets, and providing more context about the project and its features.

Future Plans: I plan to add a new query feature for retrieving an array of reviews in the future, as it can help users access more detailed information about a particular product or service. I am open to any suggestions or advice on how to approach this feature.

Contributor Experience: As someone with limited TypeScript experience, I would like to acknowledge that there may be room for further improvements in my contributions. I am eager to learn and grow, so please feel free to provide any feedback or suggestions to help me enhance my TypeScript skills and contribute better to this project.

…ADME page

i have like little to no experience with typescript. i wanted to add more features, but `ts` is different than `js`. might add a query for retrieving an array of reviews in future. let me know if there's anything to add or fix.
Copy link
Member

@codetheweb codetheweb left a comment

Choose a reason for hiding this comment

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

thanks for the contributions!

);
} catch (error: unknown) {
if (error instanceof Error) {
console.error('Error in searchSchool:', error.message);
Copy link
Member

Choose a reason for hiding this comment

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

here (and other places) we should handle the error or re-throw instead of ignoring it (this lets the caller decide what to do with it instead of the library deciding for them)

Copy link
Author

Choose a reason for hiding this comment

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

I was thinking about returning a Promise.reject or we can always add back throw error.

Copy link
Member

Choose a reason for hiding this comment

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

since this is an async function we don't have to use Promise.reject, we can just throw like normal

},
legacyId: 1234567
}
*/
Copy link
Member

Choose a reason for hiding this comment

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

I think these commented out responses are still useful to show the basic shape of the available data (open to editing it to make it a more generalized example though)

Copy link
Author

Choose a reason for hiding this comment

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

Got it, we can add them back.

README.md Outdated
```bash
npm install @mtucourses/rate-my-professors
or
yarn add @mtucourses/rate-my-professors // recommended
Copy link
Member

Choose a reason for hiding this comment

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

I personally wouldn't explictly recommend Yarn as v1 has reached its end of life

Copy link
Author

Choose a reason for hiding this comment

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

Alright, we can delete that part. No worries.

…s, changed the error handling and added `npm` package.lock
@spabolu
Copy link
Author

spabolu commented Mar 24, 2023

Hi,
I am not sure how to push the new code to the existing issue. I made another pull request with all the changes and an additional change to the URL.

@spabolu
Copy link
Author

spabolu commented Mar 24, 2023

Okay, I pushed the new code. I added changes to the URL by adding the URL as a proxy in package.json. I am hoping this would fix the problem with running the package in frontend applications. Also, I changed the README file with the changes we discussed. Let me know what you think.

"ts-node/register"
]
}
"proxy": "https://www.ratemyprofessors.com"
Copy link
Member

Choose a reason for hiding this comment

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

sorry, not clear on why this is needed

Copy link
Author

Choose a reason for hiding this comment

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

Okay, so the whole reason I stumbled upon your project is because I am trying to integrate RMP into my project called https://courseer.co/. When I tried to use the package, I get the CORS problem and after looking up online, one way to fix the issue is by adding a proxy apparently. I am not sure how exactly it fixes it, but it can help with the CORS problem when implementing your package in frontend code to retrieve ratings of the professor. If there is a better way, feel free to explain for both the package or my React project.

Copy link
Member

Choose a reason for hiding this comment

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

I believe proxy is generally only used for create react apps, I don't think it has a meaning outside of that

Copy link
Author

Choose a reason for hiding this comment

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

Interesting, but if I install your package, then it can remove the CORS issue for React apps, right? If it can remove it, then I would prefer keeping it for anyone to use in the future.

Copy link
Member

Choose a reason for hiding this comment

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

can you link to documentation to explain how this would help?

Comment on lines 106 to -90
```bash
# First:
# install dependencies
yarn install
# Install dependencies
npm install
```

# then:
# build in watch mode
yarn build:watch
## Build

# and you can:
```bash
# Build in watch mode
npm run build:watch
```

## Testing

# run tests
yarn test
```bash
# Run tests
npm test

# run tests in watch mode
yarn test:watch
Copy link
Member

Choose a reason for hiding this comment

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

very minor but I like the old format here haha

Copy link
Author

Choose a reason for hiding this comment

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

Didn't you mention that yarn is not recommended, so I just used npm for all of them.

Copy link
Member

Choose a reason for hiding this comment

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

yeah I'm fine switching to npm, just liked the old wording a bit more

);
} catch (error: unknown) {
if (error instanceof Error) {
console.error('Error in searchSchool:', error.message);
Copy link
Member

Choose a reason for hiding this comment

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

since this is an async function we don't have to use Promise.reject, we can just throw like normal

@spabolu
Copy link
Author

spabolu commented Mar 30, 2023

Looks like the changes seem accurate. We can leave the Promise.reject as it is because it doesn't bring any issues. The README is functional and I would say we can try adding the proxy to see if it can benefit frontend applications. Is it possible to merge the changes?

@spabolu
Copy link
Author

spabolu commented Apr 15, 2023

Do you know what the conflicts are? I don't have write access to fix it, so can you look into it?

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.

2 participants