fix : return orginal error
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { HttpService } from "@nestjs/axios";
|
import { HttpService } from "@nestjs/axios";
|
||||||
import { BadRequestException, Injectable, Logger } from "@nestjs/common";
|
import { BadRequestException, HttpException, Injectable, Logger } from "@nestjs/common";
|
||||||
import { Inject } from "@nestjs/common";
|
import { Inject } from "@nestjs/common";
|
||||||
import { AxiosError } from "axios";
|
import { AxiosError } from "axios";
|
||||||
import { catchError, firstValueFrom, throwError } from "rxjs";
|
import { catchError, firstValueFrom, throwError } from "rxjs";
|
||||||
@@ -66,12 +66,14 @@ export class RestaurantService {
|
|||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
// Return validation errors or other error types from external API
|
if (error instanceof AxiosError && error.response) {
|
||||||
if (error instanceof AxiosError && error.response?.data) {
|
|
||||||
this.logger.error(`External API error response:`, error.response.data);
|
this.logger.error(`External API error response:`, error.response.data);
|
||||||
return error.response.data;
|
const errorResponse = {
|
||||||
|
...error.response.data,
|
||||||
|
message: error.response.data.error?.message || error.message,
|
||||||
|
};
|
||||||
|
throw new HttpException(errorResponse, error.response.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.error(`Error fetching restaurants: ${error instanceof Error ? error.message : "Unknown error"}`);
|
this.logger.error(`Error fetching restaurants: ${error instanceof Error ? error.message : "Unknown error"}`);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -110,12 +112,14 @@ export class RestaurantService {
|
|||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
// Return validation errors or other error types from external API
|
if (error instanceof AxiosError && error.response) {
|
||||||
if (error instanceof AxiosError && error.response?.data) {
|
|
||||||
this.logger.error(`External API error response:`, error.response.data);
|
this.logger.error(`External API error response:`, error.response.data);
|
||||||
return error.response.data;
|
const errorResponse = {
|
||||||
|
...error.response.data,
|
||||||
|
message: error.response.data.error?.message || error.message,
|
||||||
|
};
|
||||||
|
throw new HttpException(errorResponse, error.response.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.error(`Error creating restaurant: ${error instanceof Error ? error.message : "Unknown error"}`);
|
this.logger.error(`Error creating restaurant: ${error instanceof Error ? error.message : "Unknown error"}`);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -137,12 +141,14 @@ export class RestaurantService {
|
|||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
// Return validation errors or other error types from external API
|
if (error instanceof AxiosError && error.response) {
|
||||||
if (error instanceof AxiosError && error.response?.data) {
|
|
||||||
this.logger.error(`External API error response:`, error.response.data);
|
this.logger.error(`External API error response:`, error.response.data);
|
||||||
return error.response.data;
|
const errorResponse = {
|
||||||
|
...error.response.data,
|
||||||
|
message: error.response.data.error?.message || error.message,
|
||||||
|
};
|
||||||
|
throw new HttpException(errorResponse, error.response.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.error(`Error getting restaurant subscription: ${error instanceof Error ? error.message : "Unknown error"}`);
|
this.logger.error(`Error getting restaurant subscription: ${error instanceof Error ? error.message : "Unknown error"}`);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -165,12 +171,14 @@ export class RestaurantService {
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
// Return validation errors or other error types from external API
|
if (error instanceof AxiosError && error.response) {
|
||||||
if (error instanceof AxiosError && error.response?.data) {
|
|
||||||
this.logger.error(`External API error response:`, error.response.data);
|
this.logger.error(`External API error response:`, error.response.data);
|
||||||
return error.response.data;
|
const errorResponse = {
|
||||||
|
...error.response.data,
|
||||||
|
message: error.response.data.error?.message || error.message,
|
||||||
|
};
|
||||||
|
throw new HttpException(errorResponse, error.response.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.error("error in getSmsCountByRestaurant", error);
|
this.logger.error("error in getSmsCountByRestaurant", error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user