Skip to content
Snippets Groups Projects
Commit 4effe713 authored by vkovtun's avatar vkovtun
Browse files

BIS-753: Merged the changes from master. Using Error objects instead of...

BIS-753: Merged the changes from master. Using Error objects instead of strings for errors in promises.
parent e3322cc0
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
......@@ -72,19 +72,19 @@ _DataStoreServerInternal.prototype.sendHttpRequest = function(httpMethod, conten
break;
}
default: {
reject("Client error HTTP response. Unsupported content-type received.");
reject(new Error("Client error HTTP response. Unsupported content-type received."));
break;
}
}
} else if (status >= 400 && status < 600) {
if (response.size > 0) {
response.text().then((blobResponse) => reject(JSON.parse(blobResponse).error[1].message))
response.text().then((blobResponse) => reject(new Error(JSON.parse(blobResponse).error[1].message)))
.catch((error) => reject(error));
} else {
reject(xhr.statusText);
reject(new Error(xhr.statusText));
}
} else {
reject("ERROR: " + xhr.responseText);
reject(new Error("ERROR: " + xhr.responseText));
}
}
};
......@@ -167,7 +167,7 @@ function parseJsonResponse(rawResponse) {
return new Promise((resolve, reject) => {
let response = JSON.parse(rawResponse);
if (response.error) {
reject(response.error[1].message);
reject(new Error(response.error[1].message));
} else {
resolve(response);
}
......
......@@ -37,17 +37,13 @@ export default class DataBrowserController extends ComponentController {
}
async listFiles() {
return new Promise((resolve, reject) => {
this.component.datastoreServer.list(this.owner, this.path, false, (data) => {
if (!data.error) {
const results = data.result[1]
const files = results.map(result => result[1])
resolve(files)
} else {
reject(data.error)
}
})
})
const data = await this.component.datastoreServer.list(this.owner, this.path, false)
if (!data.error) {
const results = data.result[1]
return results.map(result => result[1])
} else {
throw new Error(data.error)
}
}
async load() {
......@@ -63,33 +59,17 @@ export default class DataBrowserController extends ComponentController {
}
async createNewFolder(name) {
return new Promise((resolve, reject) => {
this.component.datastoreServer.create(this.owner, this.path + name, true, async (response) => {
if (response) {
if (this.gridController) {
await this.gridController.load()
}
resolve()
} else {
reject()
}
})
})
await this.component.datastoreServer.create(this.owner, this.path + name, true)
if (this.gridController) {
await this.gridController.load()
}
}
async rename(oldName, newName) {
return new Promise((resolve, reject) => {
this.component.datastoreServer.move(this.owner, this.path + oldName, this.owner, this.path + newName, async (response) => {
if (response) {
if (this.gridController) {
await this.gridController.load()
}
resolve()
} else {
reject()
}
})
})
await this.component.datastoreServer.move(this.owner, this.path + oldName, this.owner, this.path + newName)
if (this.gridController) {
await this.gridController.load()
}
}
async delete(files) {
......@@ -103,15 +83,7 @@ export default class DataBrowserController extends ComponentController {
}
async _delete(file) {
return new Promise((resolve, reject) => {
this.component.datastoreServer.delete(this.owner, file.path, async (response) => {
if (response) {
resolve()
} else {
reject()
}
})
})
await this.component.datastoreServer.delete(this.owner, file.path)
}
async copy(files, newLocation) {
......@@ -126,15 +98,7 @@ export default class DataBrowserController extends ComponentController {
async _copy(file, newLocation){
const cleanNewLocation = this._removeLeadingSlash(newLocation) + file.name
return new Promise((resolve, reject) => {
this.component.datastoreServer.copy(this.owner, file.path, this.owner, cleanNewLocation, async (response) => {
if (response) {
resolve()
} else {
reject()
}
})
})
await this.component.datastoreServer.copy(this.owner, file.path, this.owner, cleanNewLocation)
}
async move(files, newLocation) {
......@@ -149,15 +113,7 @@ export default class DataBrowserController extends ComponentController {
async _move(file, newLocation){
const cleanNewLocation = this._removeLeadingSlash(newLocation) + file.name
return new Promise((resolve, reject) => {
this.component.datastoreServer.move(this.owner, file.path, this.owner, cleanNewLocation, async (response) => {
if (response) {
resolve()
} else {
reject()
}
})
})
await this.component.datastoreServer.move(this.owner, file.path, this.owner, cleanNewLocation)
}
async download(file) {
......@@ -174,16 +130,8 @@ export default class DataBrowserController extends ComponentController {
}
async _download(file, offset) {
return new Promise((resolve, reject) => {
const limit = Math.min(MAX_READ_SIZE_IN_BYTES, file.size - offset)
this.component.datastoreServer.read(this.owner, file.path, offset, limit, async (responseData) => {
if (responseData) {
resolve(responseData)
} else {
reject()
}
})
})
const limit = Math.min(MAX_READ_SIZE_IN_BYTES, file.size - offset)
return await this.component.datastoreServer.read(this.owner, file.path, offset, limit)
}
_removeLeadingSlash(path) {
......@@ -197,5 +145,4 @@ export default class DataBrowserController extends ComponentController {
setPath(path) {
this.path = path
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment