Give error feedback if the requested file does not exist

This commit is contained in:
Johannes Zellner
2017-08-20 18:47:13 +02:00
parent 82380b6b7c
commit 4ca7cccdae
3 changed files with 47 additions and 5 deletions

View File

@@ -68,6 +68,14 @@ angular.module('Application').service('Client', ['$http', 'md5', 'Notification',
return $http.get(client.apiOrigin + url, config);
}
function head(url, config) {
config = config || {};
config.headers = config.headers || {};
config.headers.Authorization = 'Bearer ' + token;
return $http.head(client.apiOrigin + url, config);
}
function post(url, data, config) {
data = data || {};
config = config || {};
@@ -1114,6 +1122,15 @@ angular.module('Application').service('Client', ['$http', 'md5', 'Notification',
}).error(defaultErrorHandler(callback));
};
Client.prototype.checkDownloadableFile = function (appId, filePath, callback) {
head('/api/v1/apps/' + appId + '/download?file=' + filePath, {
headers: { 'Content-Type': undefined }
}).success(function(data, status) {
if (status !== 200) return callback(new ClientError(status, data));
callback(null);
}).error(defaultErrorHandler(callback));
};
client = new Client();
return client;
}]);