added error checking and updated demo
This commit is contained in:
@ -7,6 +7,10 @@ export class Drawing extends XmlComponent {
|
||||
constructor(imageData: IData) {
|
||||
super("w:drawing");
|
||||
|
||||
if (imageData === undefined) {
|
||||
throw new Error("imageData cannot be undefined");
|
||||
}
|
||||
|
||||
this.root.push(new Inline(imageData.referenceId));
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,14 @@ export class Media {
|
||||
this.map = new Map<string, IData>();
|
||||
}
|
||||
|
||||
public getMedia(key: string): IData | undefined {
|
||||
return this.map.get(key);
|
||||
public getMedia(key: string): IData {
|
||||
const data = this.map.get(key);
|
||||
|
||||
if (data === undefined) {
|
||||
throw new Error(`Cannot find image with the key ${key}`);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public addMedia(key: string, filePath: string): void {
|
||||
|
Reference in New Issue
Block a user