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

feat: add request library and cache hook, automatically generate request #18

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

1379255913
Copy link
Contributor

@1379255913 1379255913 commented Dec 16, 2024

Resolves #4

  1. 添加请求库axios,配置请求拦截器和响应拦截器,并在发生cookies、id、access-token等失效时尝试重新请求获取
  2. 添加缓存hook usePersistedQuery,在后端发生报错时使用缓存的数据
  3. 添加自动生成请求库,自动通过接口文档生成请求,使用方法写在readme

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 19 changed files in this pull request and generated 2 comments.

Files not reviewed (13)
  • package.json: Language not supported
  • app/_layout.tsx: Evaluated as low risk
  • README.md: Evaluated as low risk
  • api/generate/user.ts: Evaluated as low risk
  • api/generate/types.ts: Evaluated as low risk
  • components/Provider.tsx: Evaluated as low risk
  • api/generate/launchScreen.ts: Evaluated as low risk
  • app/(tabs)/index.tsx: Evaluated as low risk
  • api/enum.ts: Evaluated as low risk
  • api/generate/academic.ts: Evaluated as low risk
  • api/generate/authorization.ts: Evaluated as low risk
  • openapi-ts-request.config.ts: Evaluated as low risk
  • utils/user.ts: Evaluated as low risk
Comments suppressed due to low confidence (3)

api/axios.ts:79

  • The error handling for JWCH cookie exception is incomplete. Please provide a clear and helpful error message.
// TODO 尝试重新登录并获取cookies和id

hooks/usePersistedQuery.ts:31

  • Ensure that queryKey is always a string and properly sanitized to avoid potential issues with special characters.
const persistedData = await AsyncStorage.getItem(queryKey.join('__'));

hooks/usePersistedQuery.ts:40

  • [nitpick] Include a more descriptive error message to provide better context for debugging.
console.error(error);

return request(config);
} catch (error: any) {
if (error?.data?.code === ResultEnum.AuthRefreshExpiredCode) {
//TODO 重新输入账号密码登录
Copy link
Preview

Copilot AI Dec 19, 2024

Choose a reason for hiding this comment

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

The error handling for expired refresh token is incomplete. Please provide a clear and helpful error message.

Suggested change
//TODO 重新输入账号密码登录
console.error('Refresh token has expired. Please log in again.');

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
queue = [];
return request(config);
} catch (error) {
// TODO 判断是否为密码错误
Copy link
Preview

Copilot AI Dec 19, 2024

Choose a reason for hiding this comment

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

The error handling for password error is incomplete. Please provide a clear and helpful error message.

Suggested change
// TODO 判断是否为密码错误
console.error('Password error: Please check your credentials and try again.');

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Member

@renbaoshuo renbaoshuo left a comment

Choose a reason for hiding this comment

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

Build failed 了,先 block 住看看

Copy link
Member

@renbaoshuo renbaoshuo left a comment

Choose a reason for hiding this comment

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

先前无法构建的原因是分配的内存不足。在将 android\gradle.properties 中的 org.gradle.jvmargs 一项调整为 -Xmx8192m -XX:MaxMetaspaceSize=512m 后成功构建。

@renbaoshuo renbaoshuo merged commit 32cbcf9 into master Dec 19, 2024
1 check failed
@renbaoshuo renbaoshuo deleted the feature-request branch December 19, 2024 14:51
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