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: make error messages more clear #1166

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
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
@@ -1,5 +1,4 @@
/* eslint-disable max-lines */
import axios from "axios";
import { UUID } from "crypto";
import { useParams, useRouter } from "next/navigation";
import { useCallback, useState } from "react";
Expand All @@ -11,6 +10,7 @@ import { useNotificationApi } from "@/lib/api/notification/useNotificationApi";
import { useUploadApi } from "@/lib/api/upload/useUploadApi";
import { useChatContext } from "@/lib/context";
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
import { getAxiosErrorParams } from "@/lib/helpers/getAxiosErrorParams";
import { useToast } from "@/lib/hooks";

import { FeedItemCrawlType, FeedItemType, FeedItemUploadType } from "../types";
Expand Down Expand Up @@ -66,12 +66,22 @@ export const useKnowledgeUploader = ({
});
await fetchNotifications(chat_id);
} catch (error: unknown) {
publish({
variant: "danger",
text: t("crawlFailed", {
message: JSON.stringify(error),
}),
});
const errorParams = getAxiosErrorParams(error);
if (errorParams !== undefined) {
publish({
variant: "danger",
text: t("crawlFailed", {
message: JSON.stringify(errorParams.message),
}),
});
} else {
publish({
variant: "danger",
text: t("crawlFailed", {
message: JSON.stringify(error),
}),
});
}
}
},
[crawlWebsiteUrl, publish, t]
Expand All @@ -88,21 +98,20 @@ export const useKnowledgeUploader = ({
chat_id,
});
} catch (e: unknown) {
if (axios.isAxiosError(e) && e.response?.status === 403) {
const errorParams = getAxiosErrorParams(e);
if (errorParams !== undefined) {
publish({
variant: "danger",
text: `${JSON.stringify(
(
e.response as {
data: { detail: string };
}
).data.detail
)}`,
text: t("uploadFailed", {
message: JSON.stringify(errorParams.message),
}),
});
} else {
publish({
variant: "danger",
text: t("error", { message: e }),
text: t("uploadFailed", {
message: JSON.stringify(e),
}),
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export const NotificationDisplayer = ({
const { message, status, name } = JSON.parse(
nonParsedMessage.replace(/'/g, '"')
) as NotificationMessage;
console.log({
message,
status,
name,
});

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/en/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dragAndDrop":"Drag and drop files here, or click to browse",
"webSite": "Insert website URL",
"success": "File uploaded successfully",
"error": "Failed to upload file: {{message}}",
"uploadFailed": "Failed to upload file: {{message}}",
"maxSizeError": "File too big",
"alreadyAdded": "{{fileName}} was already added",
"addFiles": "Please, add files to upload",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/es/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"crawlFailed": "Error al rastrear sitio web: {{message}}",
"dragAndDrop": "Arrastre y suelte archivos aquí o click para buscar",
"drop": "Suelte los archivos aquí...",
"error": "Error al subir archivo: {{message}}",
"uploadFailed": "Error al subir archivo: {{message}}",
"invalidUrl": "URL inválido",
"maxSizeError": "Tamaño de archivo excedido",
"missingNecessaryRole": "No tienes el rol necesario para cargar contenido en el cerebro seleccionado. 🧠💡🥲",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/fr/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dragAndDrop": "Glissez et déposez les fichiers ici, ou cliquez pour parcourir",
"webSite": "Insérer l'URL du site web",
"success": "Fichier téléchargé avec succès",
"error": "Échec du téléchargement du fichier : {{message}}",
"uploadFailed": "Échec du téléchargement du fichier : {{message}}",
"maxSizeError": "Fichier trop volumineux",
"alreadyAdded": "{{fileName}} a déjà été ajouté",
"addFiles": "Veuillez ajouter des fichiers à télécharger",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/pt-br/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dragAndDrop": "Arraste e solte os arquivos aqui, ou clique para procurar",
"webSite": "Insira o URL do site",
"success": "Arquivo enviado com sucesso",
"error": "Falha ao enviar arquivo: {{message}}",
"uploadFailed": "Falha ao enviar arquivo: {{message}}",
"maxSizeError": "Arquivo muito grande",
"alreadyAdded": "{{fileName}} já foi adicionado",
"addFiles": "Por favor, adicione arquivos para enviar",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/ru/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dragAndDrop": "Перетащите файлы сюда или нажмите, чтобы выбрать",
"webSite": "Вставьте URL веб-сайта",
"success": "Файл успешно загружен",
"error": "Не удалось загрузить файл: {{message}}",
"uploadFailed": "Не удалось загрузить файл: {{message}}",
"maxSizeError": "Файл слишком большой",
"alreadyAdded": "{{fileName}} уже добавлен",
"addFiles": "Пожалуйста, добавьте файлы для загрузки",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/zh-cn/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dragAndDrop": "将文件拖放到此处,或单击浏览",
"webSite": "插入网站URL",
"success": "文件上传成功",
"error": "上传文件失败:{{message}}",
"uploadFailed": "上传文件失败:{{message}}",
"maxSizeError": "文件太大",
"alreadyAdded": "已添加 {{filename}}",
"addFiles": "请添加要上传的文件",
Expand Down