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

Api cleanup #133

Merged
merged 6 commits into from
Oct 25, 2024
Merged

Api cleanup #133

merged 6 commits into from
Oct 25, 2024

Conversation

adamgall
Copy link
Contributor

@adamgall adamgall commented Oct 14, 2024

This PR was created in response to the TODO in SignedMessageForm, in the middle of the button click which triggers an API call.

(async () => {
setIsCreating(true);
setError("");
try {
const res = await Api.createCredentials({
body: value,
query: {
operator_type: operatorType,
},
});
// TODO: consider folding the .error/.data handling into the `Api` client.
if (res.error) {
setError(res.error as string);
}
if (!res.data) {
console.log("missing .data and .error", res);
setError("invalid response (missing .data and .error)");
}
onCredentialCreated(res.data as AccessCredential);
} catch (err) {
console.log("error", err);
setError(err ? (err as string) : "Unknown error");
} finally {
setIsCreating(false);
}
})().catch(() => {});

I took the liberty of just generally "cleaning up" the Api object, to enforce more proper typing for requests and responses (no more anys), as well as consolidate all data parsing and error handling into the shared internal rpc function.

Other auxiliary changes in this PR include:

  • Adding typing to the environment variables
  • Including a vite plugin which informs the dev of any typescript issues in the project, in the npm run dev console.
  • Removing unused and derive-able props from the SignedMessageForm component

Remove unused `options`, change `body` type to `string`, mark both `body` and `options` as required. This is just to tighten the typing to how it's actually being used.
Remove unused props, and remove props that can be derived from others
Allow each API response (there's only one though) to have it's own strict type definition.
This plugin will tell you (the dev) (in the console in your `npm run dev` session) if there are any typescript issues.
Consolidate data parsing and error handling into shared Api `res` function. Accept handler callback functions for when data is successfully parsed, or errors happen, and when processing is complete.
@jshufro jshufro merged commit cf348aa into Rocket-Rescue-Node:master Oct 25, 2024
2 checks passed
@adamgall adamgall deleted the api-cleanup branch October 25, 2024 13:52
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.

3 participants