Skip to content

Commit

Permalink
feat: update api response 401 view
Browse files Browse the repository at this point in the history
  • Loading branch information
Licoy committed Sep 19, 2023
1 parent fc8ac83 commit 5694f97
Show file tree
Hide file tree
Showing 2 changed files with 386 additions and 32 deletions.
22 changes: 3 additions & 19 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,27 +510,11 @@ export const useChatStore = create<ChatStore>()(
}
if (!res.ok) {
const text = await res.text();
throw new Error(
`\n${Locale.Midjourney.StatusCode(
res.status,
)}\n${Locale.Midjourney.RespBody(
text || Locale.Midjourney.None,
)}`,
);
}
const resJson = await res.json();
if (
res.status < 200 ||
res.status >= 300 ||
resJson.code !== 0
) {
botMessage.content = Locale.Midjourney.TaskSubmitErr(
resJson?.msg ||
resJson?.error ||
resJson?.description ||
Locale.Midjourney.UnknownError,
botMessage.content = res.status === 401 ? `${Locale.Error.Unauthorized}\n\`\`\`json\n${text}\n\`\`\`\n` : Locale.Midjourney.TaskSubmitErr(
text || Locale.Midjourney.UnknownError,
);
} else {
const resJson = await res.json();
const taskId: string = resJson.taskId;
const prefixContent = Locale.Midjourney.TaskPrefix(
prompt,
Expand Down
Loading

0 comments on commit 5694f97

Please sign in to comment.