Skip to content

Commit

Permalink
resources: remove error handling from projects
Browse files Browse the repository at this point in the history
 methods.
  • Loading branch information
narekhovhannisyan committed Nov 9, 2023
1 parent 437453f commit 74146d1
Showing 1 changed file with 10 additions and 39 deletions.
49 changes: 10 additions & 39 deletions src/lib/api/resources/Projects.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { AxiosInstance } from "axios";

import handleSendingError from "../../axios-logger";

import CONFIG from "../../../config";

import { Project } from "../../../types/api/projects";
Expand All @@ -27,45 +25,28 @@ export default class ProjectsApi {
*/
public async create(projectName: string) {
const data = { project: { name: projectName } };
const apiResponse = await this.client.post<Project>(this.projectsURL, data);

try {
const apiResponse = await this.client.post<Project>(
this.projectsURL,
data
);

return apiResponse.data;
} catch (error) {
return handleSendingError(error);
}
return apiResponse.data;
}

/**
* Lists projects and their inboxes to which the API token has access.
*/
public async getList() {
try {
const apiResponse = await this.client.get<Project[]>(this.projectsURL);
const apiResponse = await this.client.get<Project[]>(this.projectsURL);

return apiResponse.data;
} catch (error) {
return handleSendingError(error);
}
return apiResponse.data;
}

/**
* Gets the project and it's inboxes.
*/
public async getById(projectId: number) {
const url = `${this.projectsURL}/${projectId}`;
const apiResponse = await this.client.get<Project>(url);

try {
const apiResponse = await this.client.get<Project>(url);

return apiResponse.data;
} catch (error) {
return handleSendingError(error);
}
return apiResponse.data;
}

/**
Expand All @@ -74,28 +55,18 @@ export default class ProjectsApi {
public async update(projectId: number, updatedName: string) {
const url = `${this.projectsURL}/${projectId}`;
const data = { project: { name: updatedName } };
const apiResponse = await this.client.patch<Project>(url, data);

try {
const apiResponse = await this.client.patch<Project>(url, data);

return apiResponse.data;
} catch (error) {
return handleSendingError(error);
}
return apiResponse.data;
}

/**
* Deletes a project by its ID.
*/
public async delete(projectId: number) {
const url = `${this.projectsURL}/${projectId}`;
const apiResponse = await this.client.delete<Project>(url);

try {
const apiResponse = await this.client.delete<Project>(url);

return apiResponse.data;
} catch (error) {
return handleSendingError(error);
}
return apiResponse.data;
}
}

0 comments on commit 74146d1

Please sign in to comment.