Skip to content

fix: After trying voice playback three times and sending an error message, an error message pops up #2772

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

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ class AudioManage {
.then(async (res: any) => {
if (res.type === 'application/json') {
const text = await res.text()
MsgError(text)
if (this.tryList[index] >= 3) {
MsgError(text)
}
this.statusList[index] = AudioStatus.ERROR
throw ''
}
Expand Down Expand Up @@ -375,8 +377,9 @@ class AudioManage {
.then(async (res: any) => {
if (res.type === 'application/json') {
const text = await res.text()
MsgError(text)

if (this.tryList[index] >= 3) {
MsgError(text)
}
throw ''
}
// 假设我们有一个 MP3 文件的字节数组
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code snippet provided appears to be part of an AudioManage class responsible for handling audio processing. Here are some points that need attention:

  1. Potential Issues:

    • The MsgError(text) function might not handle errors appropriately in all cases.
    • The MsgError(text) function is conditionally called based on the value of this.tryList[index], which could lead to duplicate error messages being logged.
    • There are redundant comments about creating a byte array, which can be removed.
  2. Optimization Suggestions:

    • Consider adding logging at the beginning and end of each .then() block to trace through the flow more easily.
    • If MsgError(text) is supposed to log different types of errors, consider parameterizing it with an error level (e.g., INFO, WARNING, ERROR).

Here's a simplified version of the relevant section with additional logging:

class AudioManage {
  tryList: number[] = [];
  statusList: AudioStatus[] = [];

  processAudio(res: any, index: number): void {
    console.log(`Processing response for index ${index}`);
    res
      .type.startsWith('application/json')
      ? this.handleError(res.text(), index)
      : this.handleNonJsonResponse(index);
  }

  handleError(text: string, index: number): void {
    console.log(`Received JSON response for index ${index}, attempting error message`);
    if (this.tryList[index] >= 3) {
      MsgError(text);
    }
    this.statusList[index] = AudioStatus.ERROR;
    throw '';
  }

  handleNonJsonResponse(index: number): void {
    // Handle non-JSON responses here...
  }
}

Note: This refactored version includes better variable names (processAudio), logging, and simplifies the logic by separating concerns into separate methods. Adjustments may be necessary depending on the context and requirements.

Expand Down