diff --git a/lib/avatar.php b/lib/avatar.php
index 1ee1e5e742f65f49a97955beac386aa8f6c5da7c..49c8270915494901a633d81f8b5a90fa94be9e3b 100644
--- a/lib/avatar.php
+++ b/lib/avatar.php
@@ -65,11 +65,13 @@ class OC_Avatar {
 			$type = substr($img->mimeType(), -3);
 			if ($type === 'peg') { $type = 'jpg'; }
 			if ($type !== 'jpg' && $type !== 'png') {
-				throw new Exception("Unknown filetype for avatar");
+				$l = \OC_L10N::get('lib');
+				throw new \Exception($l->t("Unknown filetype for avatar"));
 			}
 
 			if (!( $img->valid() && ($img->height() === $img->width()) )) {
-				throw new Exception("Invalid image, or the provided image is not square");
+				$l = \OC_L10N::get('lib');
+				throw new \Exception($l->t("Invalid image, or the provided image is not square"));
 			}
 
 			$view->unlink('avatar.jpg');
diff --git a/settings/ajax/newavatar.php b/settings/ajax/newavatar.php
index bede15e499d5ab652d776d74785e114a0b260e09..126f3283fb32bdc203dd0f295c3a0c7853de109d 100644
--- a/settings/ajax/newavatar.php
+++ b/settings/ajax/newavatar.php
@@ -4,28 +4,30 @@ OC_JSON::checkLoggedIn();
 OC_JSON::callCheck();
 $user = OC_User::getUser();
 
-if(isset($_POST['path'])) {
-	if ($_POST['path'] === "false") { // delete avatar
-		\OC_Avatar::setLocalAvatar($user, false);
-	} else { // select an image from own files
-		try {
-			$path = OC::$SERVERROOT.'/data/'.$user.'/files'.$_POST['path'];
-			\OC_Avatar::setLocalAvatar($user, $path);
-			OC_JSON::success();
-		} catch (Exception $e) {
-			OC_JSON::error(array("msg" => $e->getMessage()));
-		}
-	}
-} elseif (!empty($_FILES)) { // upload a new image
+// Delete avatar
+if (isset($_POST['path']) && $_POST['path'] === "false") {
+	$avatar = false;
+}
+// Select an image from own files
+elseif (isset($_POST['path'])) {
+	//SECURITY TODO FIXME possible directory traversal here
+	$path = $_POST['path'];
+	$avatar = OC::$SERVERROOT.'/data/'.$user.'/files'.$path;
+}
+// Upload a new image
+elseif (!empty($_FILES)) {
 	$files = $_FILES['files'];
 	if ($files['error'][0] === 0) {
-		$data = file_get_contents($files['tmp_name'][0]);
-		\OC_Avatar::setLocalAvatar($user, $data);
+		$avatar = file_get_contents($files['tmp_name'][0]);
 		unlink($files['tmp_name'][0]);
-		OC_JSON::success();
-	} else {
-		OC_JSON::error();
 	}
 } else {
 	OC_JSON::error();
 }
+
+try {
+	\OC_Avatar::setLocalAvatar($user, $avatar);
+	OC_JSON::success();
+} catch (\Exception $e) {
+	OC_JSON::error(array("data" => array ("message" => $e->getMessage()) ));
+}
diff --git a/settings/js/personal.js b/settings/js/personal.js
index 5d4422e48d7f72e81ff7a331494c33790556e96d..ae939aaa9e6be43434ad6d8f9d59d009924a4602 100644
--- a/settings/js/personal.js
+++ b/settings/js/personal.js
@@ -45,8 +45,13 @@ function changeDisplayName(){
 }
 
 function selectAvatar (path) {
-	$.post(OC.filePath('settings', 'ajax', 'newavatar.php'), {path: path});
-	updateAvatar();
+	$.post(OC.filePath('settings', 'ajax', 'newavatar.php'), {path: path}, function(data) {
+		if (data.status === "success") {
+			updateAvatar();
+		} else {
+			OC.dialogs.alert(data.data.message, t('core', "Error"));
+		}
+	});
 }
 
 function updateAvatar () {
@@ -143,8 +148,12 @@ $(document).ready(function(){
 	});
 
 	var uploadparms = {
-		done: function(e) {
-			updateAvatar();
+		done: function(e, data) {
+			if (data.result.status === "success") {
+				updateAvatar();
+			} else {
+				OC.dialogs.alert(data.result.data.message, t('core', "Error"));
+			}
 		}
 	};