evado-api-base
Advanced tools
Comparing version 4.4.1 to 4.4.2
@@ -17,3 +17,4 @@ /** | ||
'model/DataHistory': require('../model/DataHistory'), | ||
'model/RawFile': require('../model/RawFile'), | ||
}; |
@@ -18,8 +18,13 @@ /** | ||
}); | ||
if (!await raw.upload(this.getPostParams())) { | ||
return this.sendText(this.translate(raw.getFirstError()), 400); | ||
raw.setData(this.getPostParams()); | ||
if (!await raw.save()) { | ||
return this.sendText(this.translate(raw.getFirstError()), Response.BAD_REQUEST); | ||
} | ||
const id = raw.getId(); | ||
const url = await raw.getSignedUploadUrl(); | ||
this.sendJson({id, url}); | ||
try { | ||
const id = raw.getId(); | ||
const url = await raw.getSignedUploadUrl(); | ||
this.sendJson({id, url}); | ||
} catch (err) { | ||
this.handleError(err, raw.getStorage()); | ||
} | ||
} | ||
@@ -32,4 +37,8 @@ | ||
const behavior = this.createFileBehavior(model); | ||
const url = await behavior.getSignedDownloadUrl(); | ||
this.sendText(url); | ||
try { | ||
const url = await behavior.getSignedDownloadUrl(); | ||
this.sendText(url); | ||
} catch (err) { | ||
this.handleError(err, behavior.getStorage()); | ||
} | ||
} | ||
@@ -40,5 +49,18 @@ | ||
} | ||
handleError (data, storage) { | ||
if (storage.isConnectionError(data)) { | ||
return this.handleConnectionError(...arguments); | ||
} | ||
throw data; | ||
} | ||
handleConnectionError (data) { | ||
this.log('error', data); | ||
this.send('Service is unavailable. Try again later', Response.SERVICE_UNAVAILABLE); | ||
} | ||
}; | ||
module.exports.init(module); | ||
const BadRequest = require('areto/error/http/BadRequest'); | ||
const BadRequest = require('areto/error/http/BadRequest'); | ||
const Response = require('areto/web/Response'); |
{ | ||
"name": "evado-api-base", | ||
"version": "4.4.1", | ||
"version": "4.4.2", | ||
"description": "Evado Framework data access API module", | ||
@@ -5,0 +5,0 @@ "author": { |
62319
25
1407