Skip to content

Commit

Permalink
update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Germey committed Dec 31, 2023
1 parent 2c9bf1d commit c56ab79
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/chat/InputBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default defineComponent({
border-radius: 10px;
background: none;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
top: 40px;
top: 50px;
.upload {
display: inline-block;
&.disabled {
Expand Down
39 changes: 34 additions & 5 deletions src/components/chat/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</div>
</div>
<answering-mark v-if="message.state === messageState.PENDING" />
<el-alert v-if="errorText && message.role === 'assistant'" :title="errorText" type="error" :closable="false" />
</div>
<div class="operations">
<copy-to-clipboard v-if="!Array.isArray(message.content)" :content="message.content" class="btn-copy" />
Expand All @@ -20,10 +21,19 @@
import { defineComponent } from 'vue';
import AnsweringMark from './AnsweringMark.vue';
import copy from 'copy-to-clipboard';
import { ElImage } from 'element-plus';
import { ElAlert } from 'element-plus';
import MarkdownRenderer from '@/components/common/MarkdownRenderer.vue';
import { IChatMessage, IChatMessageState } from '@/operators';
import CopyToClipboard from '../common/CopyToClipboard.vue';
import {
ERROR_CODE_API_ERROR,
ERROR_CODE_BAD_REQUEST,
ERROR_CODE_CONTENT_TOO_LARGE,
ERROR_CODE_TIMEOUT,
ERROR_CODE_TOO_MANY_REQUESTS,
ERROR_CODE_UNKNOWN,
ERROR_CODE_USED_UP
} from '@/constants';
interface IData {
copied: boolean;
messageState: typeof IChatMessageState;
Expand All @@ -35,7 +45,7 @@ export default defineComponent({
CopyToClipboard,
AnsweringMark,
MarkdownRenderer,
ElImage
ElAlert
},
props: {
message: {
Expand All @@ -51,9 +61,28 @@ export default defineComponent({
};
},
computed: {
// conversationId() {
// return this.$route.params?.id?.toString();
// }
errorText() {
if (!this.message.error || !this.message.error?.code) {
return undefined;
}
switch (this.message.error?.code) {
case ERROR_CODE_USED_UP:
return this.$t('chat.message.errorUsedUp');
case ERROR_CODE_API_ERROR:
return this.$t('chat.message.errorApiError');
case ERROR_CODE_BAD_REQUEST:
return this.$t('chat.message.errorBadRequest');
case ERROR_CODE_TIMEOUT:
return this.$t('chat.message.errorTimeout');
case ERROR_CODE_TOO_MANY_REQUESTS:
return this.$t('chat.message.errorTooManyRequests');
case ERROR_CODE_CONTENT_TOO_LARGE:
return this.$t('chat.message.errorContentTooLarge');
case ERROR_CODE_UNKNOWN:
default:
return this.$t('chat.message.errorUnknown');
}
}
},
methods: {
onCopy() {
Expand Down
10 changes: 9 additions & 1 deletion src/components/chat/SidePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div
v-for="(conversation, conversationIndex) in conversations"
:key="conversationIndex"
class="conversation"
:class="{ conversation: true, active: conversation.id === conversationId }"
@click="onClick(conversation.id)"
>
<div class="icons">
Expand Down Expand Up @@ -84,6 +84,9 @@ export default defineComponent({
props: {},
emits: ['click'],
computed: {
conversationId() {
return this.$route.params?.id?.toString();
},
conversations() {
return this.$store.state.chat.conversations;
},
Expand Down Expand Up @@ -156,6 +159,11 @@ export default defineComponent({
color: #666;
cursor: pointer;
&.active,
&:hover {
background-color: #eee;
}
.icons {
width: 30px;
padding-left: 10px;
Expand Down
2 changes: 1 addition & 1 deletion src/components/midjourney/tasks/TaskPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</el-tag>
</div>
</div>
<div v-if="!full" class="extra">
<div class="extra">
<p v-if="modelValue?.request?.prompt" class="prompt">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-1" />
{{ modelValue?.request?.prompt }}
Expand Down
3 changes: 2 additions & 1 deletion src/constants/errorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ export const ERROR_CODE_DUPLICATION = 'duplication';
export const ERROR_CODE_BUSY = 'busy';
export const ERROR_CODE_API_ERROR = 'api_error';
export const ERROR_CODE_BAD_REQUEST = 'bad_request';
export const ERROR_CODE_NO_CONVERSATION = 'no_conversation';
export const ERROR_CODE_USED_UP = 'used_up';
export const ERROR_CODE_UNKNOWN = 'unknown';
export const ERROR_CODE_CANCELED = 'canceled';
export const ERROR_CODE_TIMEOUT = 'timeout';
export const ERROR_CODE_CONTENT_TOO_LARGE = 'content_too_large';
export const ERROR_CODE_TOO_MANY_REQUESTS = 'too_many_requests';
2 changes: 1 addition & 1 deletion src/pages/chat/Conversation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export default defineComponent({
}
.bottom {
width: 100%;
height: 100px;
height: 110px;
}
}
</style>

0 comments on commit c56ab79

Please sign in to comment.