make new error handling work with avatar upload
This commit is contained in:
parent
00f7ca72a5
commit
e3c0882a2e
1 changed files with 6 additions and 4 deletions
|
@ -2,7 +2,7 @@
|
|||
import { overlayStore, userInfoStore, smallViewport, theme, doAnimations, OverlayType, sendTypingUpdatesItemStore } from "../../stores";
|
||||
import { logOut } from "../../auth";
|
||||
import { maybeModalFade, maybeModalScale } from "../../animations";
|
||||
import request, { methods, remoteBlobUpload } from "../../request";
|
||||
import request, { getErrorFromResponse, methods, remoteBlobUpload, responseOk } from "../../request";
|
||||
import { apiRoute, getItem } from "../../storage";
|
||||
import UserView from "../UserView.svelte";
|
||||
import ChipBar from "../ChipBar.svelte";
|
||||
|
@ -55,11 +55,13 @@
|
|||
if (!avatarFileInput || !avatarFileInput.files || !avatarFileInput.files[0]) return;
|
||||
|
||||
const file = avatarFileInput.files[0];
|
||||
const { ok } = await remoteBlobUpload(methods.putUserAvatar, file);
|
||||
if (ok) {
|
||||
const res = await remoteBlobUpload(methods.putUserAvatar, file);
|
||||
if (responseOk(res)) {
|
||||
overlayStore.toast("Your avatar has been updated");
|
||||
} else {
|
||||
overlayStore.toast("Failed to upload avatar");
|
||||
const error = getErrorFromResponse(res);
|
||||
const message = error.validationErrors && error.validationErrors.length ? error.validationErrors[0].msg : error.message;
|
||||
overlayStore.toast(`Failed to upload avatar: ${message}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue