1
0
mirror of synced 2024-11-17 11:37:13 +01:00

Add better error handling.

Also now doesn't do anything if there's no input
This commit is contained in:
j433866 2019-01-16 16:57:58 +00:00
parent d00b0f4c0e
commit 69797e58cb

View File

@ -5,6 +5,7 @@
*/ */
import Operation from "../Operation"; import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import {FORMATS, convertCoordinates} from "../lib/ConvertCoordinates"; import {FORMATS, convertCoordinates} from "../lib/ConvertCoordinates";
/** /**
@ -37,7 +38,6 @@ class ConvertCoordinateFormat extends Operation {
"Auto", "Auto",
"Direction Preceding", "Direction Preceding",
"Direction Following", "Direction Following",
"Space",
"\\n", "\\n",
"Comma", "Comma",
"Semi-colon", "Semi-colon",
@ -83,8 +83,17 @@ class ConvertCoordinateFormat extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const [inFormat, inDelim, outFormat, outDelim, incDirection, precision] = args; if (input.replace(/[\s+]/g, "") !== "") {
return convertCoordinates(input, inFormat, inDelim, outFormat, outDelim, incDirection, precision); const [inFormat, inDelim, outFormat, outDelim, incDirection, precision] = args;
try {
const result = convertCoordinates(input, inFormat, inDelim, outFormat, outDelim, incDirection, precision);
return result;
} catch (error) {
throw new OperationError(error);
}
} else {
return input;
}
} }
} }