Skip to content
Snippets Groups Projects
helpers.ts 341 B
Newer Older
  • Learn to ignore specific revisions
  • import { HttpException } from '@nestjs/common';
    
    export function handleError(err, defaultErr) {
      if (err instanceof HttpException) {
        throw err;
      } else {
        if (err && err.error) {
          const error = JSON.parse(err.error);
          throw new HttpException(error.message, err.statusCode);
        } else {
          throw defaultErr;
        }
      }
    }