Merge branch 'custom-at' into 'v3'
Custom `from_index()` function in webapp for backwards compatibility before javascrpt `at()` Closes #396 See merge request openflexure/openflexure-microscope-server!280
This commit is contained in:
commit
60b2fda385
1 changed files with 22 additions and 2 deletions
|
|
@ -171,6 +171,26 @@ export default {
|
|||
},
|
||||
|
||||
mounted() {
|
||||
//Define .from_index() as a custom function, working similar to .at()
|
||||
//For backwards compatibility, not using in-built .at() until updates to Connect
|
||||
function from_index(n) {
|
||||
// ToInteger() abstract op
|
||||
n = Math.trunc(n) || 0;
|
||||
// Allow negative indexing from the end
|
||||
if (n < 0) n += this.length;
|
||||
// OOB access is guaranteed to return undefined
|
||||
if (n < 0 || n >= this.length) return undefined;
|
||||
// Otherwise, this is just normal property access
|
||||
return this[n];
|
||||
}
|
||||
const TypedArray = Reflect.getPrototypeOf(Int8Array);
|
||||
for (const C of [Array, String, TypedArray]) {
|
||||
Object.defineProperty(C.prototype, "from_index",
|
||||
{ value: from_index,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true });
|
||||
}
|
||||
// Check for already running tasks
|
||||
if (this.taskStarted != true) {
|
||||
this.checkExistingTasks();
|
||||
|
|
@ -299,14 +319,14 @@ export default {
|
|||
if (!this.progress) this.progress = 1;
|
||||
// Test whether the log is empty or the most recent message is not from an error
|
||||
// If so, return a default message
|
||||
if (response.data.log.length == 0 | response.data.log.at(-1).levelname != "ERROR") {
|
||||
if (response.data.log.length == 0 | response.data.log.from_index(-1).levelname != "ERROR") {
|
||||
var message = "Unexpected error, please check the logs";
|
||||
}
|
||||
// As LabThings Actions add the message from any raised exception to the log, the
|
||||
// last message in the log is the message from the Exception.
|
||||
//If the Exception was raised with no message, use a default.
|
||||
else {
|
||||
message = response.data.log.at(-1).message||"Unexpected error, please check the logs";
|
||||
message = response.data.log.from_index(-1).message||"Unexpected error, please check the logs";
|
||||
}
|
||||
// Raise an Error with the chosen message
|
||||
reject(new Error(message));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue