thekevinscott / UpscalerJS

Error objects should be used as Promise rejection reasons JS-0114
Anti-pattern
Major
4 occurrences in this check
Expected the Promise rejection reason to be an Error.
 2
 3export const getHTMLImageElement = (src: string) => new Promise<HTMLImageElement>((resolve, reject) => {
 4  let timer = setTimeout(() => {
 5    reject(`Image load timed out in ${TIMEOUT}ms. src: ${src}`); 6  }, TIMEOUT);
 7  const img = new Image();
 8  img.src = src;
Expected the Promise rejection reason to be an Error.
12    if (typeof(reader.result) === 'string') {
13      resolve(reader.result);
14    } else {
15      reject('No valid result could be found');16    }
17  };
18  reader.readAsDataURL(file);
Expected the Promise rejection reason to be an Error.
 7  const reader = new FileReader()
 8
 9  reader.onabort = () => reject('File reading was aborted');
10  reader.onerror = () => reject('File reading has failed');11  reader.onload = () => {
12    if (typeof(reader.result) === 'string') {
13      resolve(reader.result);
Expected the Promise rejection reason to be an Error.
 6const readFile = (file: File): Promise<string> => new Promise((resolve, reject) => {
 7  const reader = new FileReader()
 8
 9  reader.onabort = () => reject('File reading was aborted');10  reader.onerror = () => reject('File reading has failed');
11  reader.onload = () => {
12    if (typeof(reader.result) === 'string') {