Skip to content

Commit

Permalink
📝 Updated function comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ICEatm committed Jun 14, 2024
1 parent 3c1936e commit 56d0cdd
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/common/services/http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,25 @@ import { catchError, lastValueFrom } from 'rxjs';
export class HttpService {
constructor(private readonly httpService: NestHttpService) {}

/**
* Performs a GET request to the specified URL.
* @param url - The URL to send the GET request to.
* @param config - Optional Axios request configuration.
* @returns A promise that resolves to an AxiosResponse.
* @throws {HttpException} Throws an HttpException if the request fails.
*/
async get(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse> {
return this.handleRequest(this.httpService.get(url, config));
}

/**
* Performs a POST request to the specified URL with the given data.
* @param url - The URL to send the POST request to.
* @param data - The data to send in the POST request.
* @param config - Optional Axios request configuration.
* @returns A promise that resolves to an AxiosResponse.
* @throws {HttpException} Throws an HttpException if the request fails.
*/
async post(
url: string,
data: any,
Expand All @@ -19,6 +34,14 @@ export class HttpService {
return this.handleRequest(this.httpService.post(url, data, config));
}

/**
* Performs a PUT request to the specified URL with the given data.
* @param url - The URL to send the PUT request to.
* @param data - The data to send in the PUT request.
* @param config - Optional Axios request configuration.
* @returns A promise that resolves to an AxiosResponse.
* @throws {HttpException} Throws an HttpException if the request fails.
*/
async put(
url: string,
data: any,
Expand All @@ -27,13 +50,26 @@ export class HttpService {
return this.handleRequest(this.httpService.put(url, data, config));
}

/**
* Performs a DELETE request to the specified URL.
* @param url - The URL to send the DELETE request to.
* @param config - Optional Axios request configuration.
* @returns A promise that resolves to an AxiosResponse.
* @throws {HttpException} Throws an HttpException if the request fails.
*/
async delete(
url: string,
config?: AxiosRequestConfig,
): Promise<AxiosResponse> {
return this.handleRequest(this.httpService.delete(url, config));
}

/**
* Handles the HTTP request and catches errors to throw appropriate HttpExceptions.
* @param request - The HTTP request observable.
* @returns A promise that resolves to an AxiosResponse.
* @throws {HttpException} Throws an HttpException with the appropriate status and message.
*/
private async handleRequest(request: any): Promise<AxiosResponse> {
return await lastValueFrom(
request.pipe(
Expand Down

0 comments on commit 56d0cdd

Please sign in to comment.