@@ -21,6 +21,8 @@ import Field from "../elements/Field";
2121import { User } from "matrix-js-sdk" ;
2222import { getHostingLink } from '../../../utils/HostingLink' ;
2323import * as sdk from "../../../index" ;
24+ import Modal from "../../../Modal" ;
25+ import ErrorDialog from "../dialogs/ErrorDialog" ;
2426
2527export default class ProfileSettings extends React . Component {
2628 constructor ( ) {
@@ -84,21 +86,26 @@ export default class ProfileSettings extends React.Component {
8486 const client = MatrixClientPeg . get ( ) ;
8587 const newState = { } ;
8688
87- // TODO: What do we do about errors?
88-
89- if ( this . state . originalDisplayName !== this . state . displayName ) {
90- await client . setDisplayName ( this . state . displayName ) ;
91- newState . originalDisplayName = this . state . displayName ;
92- }
93-
94- if ( this . state . avatarFile ) {
95- const uri = await client . uploadContent ( this . state . avatarFile ) ;
96- await client . setAvatarUrl ( uri ) ;
97- newState . avatarUrl = client . mxcUrlToHttp ( uri , 96 , 96 , 'crop' , false ) ;
98- newState . originalAvatarUrl = newState . avatarUrl ;
99- newState . avatarFile = null ;
100- } else if ( this . state . originalAvatarUrl !== this . state . avatarUrl ) {
101- await client . setAvatarUrl ( "" ) ; // use empty string as Synapse 500s on undefined
89+ try {
90+ if ( this . state . originalDisplayName !== this . state . displayName ) {
91+ await client . setDisplayName ( this . state . displayName ) ;
92+ newState . originalDisplayName = this . state . displayName ;
93+ }
94+
95+ if ( this . state . avatarFile ) {
96+ const uri = await client . uploadContent ( this . state . avatarFile ) ;
97+ await client . setAvatarUrl ( uri ) ;
98+ newState . avatarUrl = client . mxcUrlToHttp ( uri , 96 , 96 , 'crop' , false ) ;
99+ newState . originalAvatarUrl = newState . avatarUrl ;
100+ newState . avatarFile = null ;
101+ } else if ( this . state . originalAvatarUrl !== this . state . avatarUrl ) {
102+ await client . setAvatarUrl ( "" ) ; // use empty string as Synapse 500s on undefined
103+ }
104+ } catch ( err ) {
105+ Modal . createTrackedDialog ( 'Failed to save profile' , '' , ErrorDialog , {
106+ title : _t ( "Failed to save your profile" ) ,
107+ description : ( ( err && err . message ) ? err . message : _t ( "The operation could not be completed" ) ) ,
108+ } ) ;
102109 }
103110
104111 this . setState ( newState ) ;
0 commit comments