diff --git a/app/app.component.ts b/app/app.component.ts index 79d9816..12cf4e3 100644 --- a/app/app.component.ts +++ b/app/app.component.ts @@ -36,12 +36,11 @@ export class AppComponent extends OnInit { if (typeof console === "object" && typeof console.log === "function") { console.log(error); } + step.message = error.message; + step.error = true; result = null; } - if (result === null) { - step.message = "Error converting. Not applicable?"; - step.error = true; - } else { + if (result !== null) { step.message = ""; step.error = false; if (result !== "") { diff --git a/app/converter/base64decoder.ts b/app/converter/base64decoder.ts index 1b4e5b1..d052ac0 100644 --- a/app/converter/base64decoder.ts +++ b/app/converter/base64decoder.ts @@ -10,6 +10,10 @@ export class Base64Decoder implements Converter { } convert(input:string):string { - return atob(input); + try { + return atob(input); + } catch (exception) { + throw new Error("Could not decode base64 string. Maybe corrupt input?"); + } } } diff --git a/app/converter/base64encoder.ts b/app/converter/base64encoder.ts index 409636d..989db7a 100644 --- a/app/converter/base64encoder.ts +++ b/app/converter/base64encoder.ts @@ -10,6 +10,10 @@ export class Base64Encoder implements Converter { } convert(input:string):string { - return btoa(input); + try { + return btoa(input); + } catch (exception) { + throw new Error("Could not encode base64 string. This should not happen, so why don't you just try again?"); + } } } diff --git a/app/converter/bintodecconverter.ts b/app/converter/bintodecconverter.ts index 2c73959..0b4cbd7 100644 --- a/app/converter/bintodecconverter.ts +++ b/app/converter/bintodecconverter.ts @@ -9,6 +9,10 @@ export class BinToDecConverter implements Converter { } convert(input:string):string { - return parseInt(input, 2).toString(10); + let n:number = parseInt(input, 2); + if (isNaN(n)) { + throw new Error("The input seems not to be a valid binary number."); + } + return n.toString(10); } } diff --git a/app/converter/dectobinconverter.ts b/app/converter/dectobinconverter.ts index 8cc2b0d..b64a310 100644 --- a/app/converter/dectobinconverter.ts +++ b/app/converter/dectobinconverter.ts @@ -9,6 +9,10 @@ export class DecToBinConverter implements Converter { } convert(input:string):string { - return parseInt(input, 10).toString(2); + let n:number = parseInt(input, 10); + if (isNaN(n)) { + throw new Error("The input seems not to be a valid integer."); + } + return n.toString(2); } } diff --git a/app/converter/dectohexconverter.ts b/app/converter/dectohexconverter.ts index c0be47f..b033792 100644 --- a/app/converter/dectohexconverter.ts +++ b/app/converter/dectohexconverter.ts @@ -1,7 +1,7 @@ import {Converter} from "./converter"; export class DecToHexConverter implements Converter { getDisplayname():string { - return "Convert decimal to heximal"; + return "Convert decimal to hexadecimal"; } getId():string { @@ -9,6 +9,10 @@ export class DecToHexConverter implements Converter { } convert(input:string):string { - return parseInt(input, 10).toString(16); + let n:number = parseInt(input, 10); + if (isNaN(n)) { + throw new Error("The input seems not to be a valid integer."); + } + return n.toString(16); } } diff --git a/app/converter/hextodecconverter.ts b/app/converter/hextodecconverter.ts index c6b3dba..2dcdad2 100644 --- a/app/converter/hextodecconverter.ts +++ b/app/converter/hextodecconverter.ts @@ -1,7 +1,7 @@ import {Converter} from "./converter"; export class HexToDecConverter implements Converter { getDisplayname():string { - return "Convert heximal to decimal"; + return "Convert hexadecimal to decimal"; } getId():string { @@ -9,6 +9,10 @@ export class HexToDecConverter implements Converter { } convert(input:string):string { - return parseInt(input, 16).toString(10); + let n:number = parseInt(input, 16); + if (isNaN(n)) { + throw new Error("The input seems not to be a valid hexadecimal number.") + } + return n.toString(10); } } diff --git a/app/converter/quotedprintabledecoder.ts b/app/converter/quotedprintabledecoder.ts index 6787ff1..d998038 100644 --- a/app/converter/quotedprintabledecoder.ts +++ b/app/converter/quotedprintabledecoder.ts @@ -14,6 +14,10 @@ export class QuotedPrintableDecoder implements Converter { } convert(input:string):string { - return this.nativeLibraryWrapperService.utf8.decode(this.nativeLibraryWrapperService.quotedPrintable.decode(input)); + try { + return this.nativeLibraryWrapperService.utf8.decode(this.nativeLibraryWrapperService.quotedPrintable.decode(input)); + } catch (error) { + throw new Error("The input can not be interpreted as quoted-printable. May be corrupt?"); + } } }