UNPKG

typerinth

Version:

A TypeScript library for interacting with the Modrinth API.

31 lines (30 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Route_1 = require("../Route"); const errors_1 = require("../../errors"); class GetVersionRoute extends Route_1.Route { versionId; constructor(baseUrl, ua, cacheManager, versionId) { super(baseUrl, ua, cacheManager); this.versionId = versionId; } getCacheKey() { return `version:${this.versionId}`; } getUrl() { return Route_1.Route.addPathSegment(this.baseUrl, `/version/${this.versionId}`); } parseData(data) { if (data === null) throw new errors_1.VersionNotFoundError('Version not found'); if (!data) throw new errors_1.UnexpectedApiError('Unexpected empty response'); if (data.error) { if (data.error === 'not_found') throw new errors_1.VersionNotFoundError('Version not found'); throw new errors_1.ApiError(data.error, data.description); } return data; } } exports.default = GetVersionRoute;