Skip to content

Commit 01949d5

Browse files
author
Markku Laine
committed
refactor(errorhandling): improve UX in error handling
1 parent 0e20e6f commit 01949d5

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

backend/aim/handlers.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import tornado.websocket
2828
from loguru import logger
2929
from motor.motor_tornado import MotorDatabase
30-
from pydantic.error_wrappers import ValidationError
3130
from selenium.webdriver.chrome.webdriver import WebDriver as ChromeWebDriver
3231
from tornado.options import options
3332

@@ -40,6 +39,7 @@
4039
METRICS_DIR,
4140
METRICS_FILE_PATTERN,
4241
)
42+
from aim.exceptions import ValidationError
4343
from aim.models import MessageBase, MessageImage, MessageInput, MessageURL
4444
from aim.tools import Screenshot
4545

@@ -246,7 +246,30 @@ def on_message(self, message: Union[str, bytes]):
246246
"session": session_id,
247247
"datetime": utils.custom_isoformat(datetime.utcnow()),
248248
"type": "ValidationError",
249-
"message": e.errors(),
249+
"message": str(e),
250+
},
251+
)
252+
253+
# Push error
254+
self.write_message(
255+
{
256+
"type": "error",
257+
"action": "pushValidationError",
258+
"message": str(e),
259+
}
260+
)
261+
except ValueError as e:
262+
logger.error("ValueError", e)
263+
264+
# Save error data
265+
self._save_data(
266+
"errors",
267+
{
268+
"server": server_name,
269+
"session": session_id,
270+
"datetime": utils.custom_isoformat(datetime.utcnow()),
271+
"type": "ValueError",
272+
"message": e.errors()[0]["msg"], # type: ignore
250273
},
251274
)
252275

@@ -255,7 +278,7 @@ def on_message(self, message: Union[str, bytes]):
255278
{
256279
"type": "error",
257280
"action": "pushValidationError",
258-
"message": e.errors(),
281+
"message": e.errors()[0]["msg"], # type: ignore
259282
}
260283
)
261284
except NotImplementedError as e:

frontend/src/components/AIMForm.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<h4 class="alert-heading">Validation Error</h4>
3131
<hr>
3232
<p>
33-
<strong>Whoops!</strong> We are having some problems with your input, please try again with a different URL or image.
33+
<strong>Whoops!</strong> We are having some problems with your input. Please refresh the page and try again with a different URL or image.
3434
</p>
3535
</div>
3636
</b-col>
@@ -66,6 +66,9 @@
6666
<div v-if="fileTooLarge" class="invalid-feedback">
6767
File is too large (max 5 MB).
6868
</div>
69+
<div class="image-min-size">
70+
Minimum size is 1280 x 800 pixels.
71+
</div>
6972
</b-form>
7073
</b-col>
7174
</b-row>
@@ -748,6 +751,13 @@ header{
748751
.input-group.is-invalid ~ .invalid-feedback {
749752
display: block;
750753
}
754+
.image-min-size {
755+
color: #999999;
756+
display: block;
757+
font-size: 80%;
758+
margin-top: 0.25rem;
759+
width: 100%;
760+
}
751761
752762
.custom-control {
753763
display: inline;

0 commit comments

Comments
 (0)