All files / src/utils error.ts

36.36% Statements 4/11
0% Branches 0/2
0% Functions 0/5
36.36% Lines 4/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44        1x                   1x         1x                       1x                        
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
 * Validation Error.
 */
export class ValidationError extends Error {
  code?: string;
  statusCode?: number;
  details: unknown[];
  field: string;
}
 
/**
 * Error utils.
 */
export class ErrorUtils {
  /**
   * Check if the result has an error.
   * @param promise_result The result of Promise.allSettled
   */
  public static hasError = (promise_result: any[]): boolean => {
    const has_error = promise_result.find(res => {
      return res.status === 'rejected';
    });
 
    return !!has_error;
  };
 
  /**
   * Build the details error when use Promise.allSettled
   * @param promise_result
   */
  public static buildErrorDetails = (promise_result: any[]): any[] => {
    return promise_result
      .map((res: any): any => {
        if (res.status === 'rejected') {
          return (res as PromiseRejectedResult).reason;
        }
      })
      .filter(err => {
        return err;
      });
  };
}