mirror of
https://github.com/dolanmiu/docx.git
synced 2026-11-30 16:47:55 +01:00
enh: replace generic error with TokenNotFoundError in findRunElementIndexWithToken (#3309)
Co-authored-by: Dolan <dolan_miu@hotmail.com>
This commit is contained in:
@@ -2,6 +2,13 @@ import { Element } from "xml-js";
|
||||
|
||||
import { createTextElementContents, patchSpaceAttribute } from "./util";
|
||||
|
||||
export class TokenNotFoundError extends Error {
|
||||
public constructor(token: string) {
|
||||
super(`Token ${token} not found`);
|
||||
this.name = "TokenNotFoundError";
|
||||
}
|
||||
}
|
||||
|
||||
export const findRunElementIndexWithToken = (paragraphElement: Element, token: string): number => {
|
||||
for (let i = 0; i < (paragraphElement.elements ?? []).length; i++) {
|
||||
const element = paragraphElement.elements![i];
|
||||
@@ -20,7 +27,7 @@ export const findRunElementIndexWithToken = (paragraphElement: Element, token: s
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("Token not found");
|
||||
throw new TokenNotFoundError(token);
|
||||
};
|
||||
|
||||
export const splitRunElement = (runElement: Element, token: string): { readonly left: Element; readonly right: Element } => {
|
||||
|
||||
Reference in New Issue
Block a user