Files
vercel/packages/cli/src/util/projects/get-project-by-id-or-name.ts
Ethan Arrowood af239b5fa5 [internals] Create @vercel-internals/types (#9608)
Moves the type file out of the cli package and into its own standalone
package. utilizes `@vercel/style-guide` too for typescript config,
eslint, and prettier.
2023-03-07 08:44:25 -07:00

24 lines
586 B
TypeScript

import Client from '../client';
import { Project } from '@vercel-internals/types';
import { isAPIError, ProjectNotFound } from '../errors-ts';
export default async function getProjectByNameOrId(
client: Client,
projectNameOrId: string,
accountId?: string
) {
try {
const project = await client.fetch<Project>(
`/v8/projects/${encodeURIComponent(projectNameOrId)}`,
{ accountId }
);
return project;
} catch (err: unknown) {
if (isAPIError(err) && err.status === 404) {
return new ProjectNotFound(projectNameOrId);
}
throw err;
}
}