Merge branch '8-display-more-specific-error-messages' into 'develop'

Resolve "Display more specific error messages"

Closes #8 and #9

See merge request !5
This commit is contained in:
Manuel Friedli 2016-09-21 23:18:21 +02:00
commit e8fb01e912
8 changed files with 40 additions and 13 deletions

View file

@ -36,12 +36,11 @@ export class AppComponent extends OnInit {
if (typeof console === "object" && typeof console.log === "function") { if (typeof console === "object" && typeof console.log === "function") {
console.log(error); console.log(error);
} }
step.message = error.message;
step.error = true;
result = null; result = null;
} }
if (result === null) { if (result !== null) {
step.message = "Error converting. Not applicable?";
step.error = true;
} else {
step.message = ""; step.message = "";
step.error = false; step.error = false;
if (result !== "") { if (result !== "") {

View file

@ -10,6 +10,10 @@ export class Base64Decoder implements Converter {
} }
convert(input:string):string { convert(input:string):string {
try {
return atob(input); return atob(input);
} catch (exception) {
throw new Error("Could not decode base64 string. Maybe corrupt input?");
}
} }
} }

View file

@ -10,6 +10,10 @@ export class Base64Encoder implements Converter {
} }
convert(input:string):string { convert(input:string):string {
try {
return btoa(input); 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?");
}
} }
} }

View file

@ -9,6 +9,10 @@ export class BinToDecConverter implements Converter {
} }
convert(input:string):string { 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);
} }
} }

View file

@ -9,6 +9,10 @@ export class DecToBinConverter implements Converter {
} }
convert(input:string):string { 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);
} }
} }

View file

@ -1,7 +1,7 @@
import {Converter} from "./converter"; import {Converter} from "./converter";
export class DecToHexConverter implements Converter { export class DecToHexConverter implements Converter {
getDisplayname():string { getDisplayname():string {
return "Convert decimal to heximal"; return "Convert decimal to hexadecimal";
} }
getId():string { getId():string {
@ -9,6 +9,10 @@ export class DecToHexConverter implements Converter {
} }
convert(input:string):string { 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);
} }
} }

View file

@ -1,7 +1,7 @@
import {Converter} from "./converter"; import {Converter} from "./converter";
export class HexToDecConverter implements Converter { export class HexToDecConverter implements Converter {
getDisplayname():string { getDisplayname():string {
return "Convert heximal to decimal"; return "Convert hexadecimal to decimal";
} }
getId():string { getId():string {
@ -9,6 +9,10 @@ export class HexToDecConverter implements Converter {
} }
convert(input:string):string { 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);
} }
} }

View file

@ -14,6 +14,10 @@ export class QuotedPrintableDecoder implements Converter {
} }
convert(input:string):string { convert(input:string):string {
try {
return this.nativeLibraryWrapperService.utf8.decode(this.nativeLibraryWrapperService.quotedPrintable.decode(input)); 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?");
}
} }
} }