UNPKG

typerinth

Version:

A TypeScript library for interacting with the Modrinth API.

32 lines (31 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetProjectRoute = void 0; const Route_1 = require("../Route"); const errors_1 = require("../../errors"); class GetProjectRoute extends Route_1.Route { projectId; constructor(baseUrl, ua, cacheManager, projectId) { super(baseUrl, ua, cacheManager); this.projectId = projectId; } getCacheKey() { return `project:${this.projectId}`; } getUrl() { return Route_1.Route.addPathSegment(this.baseUrl, `/project/${this.projectId}`); } parseData(data) { if (data === null) throw new errors_1.ProjectNotFoundError('Project not found'); if (!data) throw new errors_1.UnexpectedApiError('Unexpected empty response'); if (data.error) { if (data.error === 'not_found') throw new errors_1.ProjectNotFoundError('Project not found'); throw new errors_1.ApiError(data.error, data.description); } return data; } } exports.GetProjectRoute = GetProjectRoute;