Files
vercel/packages/cli/test/mocks/team.ts
Steven c2f1bebd1f [cli] Fix error message when token is invalid (#10131)
This changes the error when a token is invalid or expired from

```
Error: Could not retrieve Project Settings. To link your Project, remove the `.vercel` directory and deploy again.
Learn More: https://vercel.link/cannot-load-project-settings
```

to a better error

```
Error: The specified token is not valid. Use `vercel login` to generate a new token.
```

- This could be considered a follow up to
https://github.com/vercel/vercel/pull/7794
2023-06-23 11:18:58 -04:00

70 lines
1.5 KiB
TypeScript

import chance from 'chance';
import { client } from './client';
export function useTeams(
teamId?: string,
options: {
failMissingToken?: boolean;
failInvalidToken?: boolean;
failNoAccess?: boolean;
} = {
failMissingToken: false,
failInvalidToken: false,
failNoAccess: false,
}
) {
const id = teamId || chance().guid();
const teams = [
{
id,
slug: chance().string({ length: 5, casing: 'lower' }),
name: chance().company(),
creatorId: chance().guid(),
created: '2017-04-29T17:21:54.514Z',
avatar: null,
},
];
for (let team of teams) {
client.scenario.get(`/teams/${team.id}`, (_req, res) => {
if (options.failMissingToken) {
res.statusCode = 403;
res.json({
message: 'The request is missing an authentication token',
code: 'forbidden',
missingToken: true,
});
return;
}
if (options.failInvalidToken) {
res.statusCode = 403;
res.json({
message: 'Not authorized',
code: 'forbidden',
invalidToken: true,
});
return;
}
if (options.failNoAccess) {
res.statusCode = 403;
res.send({
code: 'team_unauthorized',
message: 'You are not authorized',
});
return;
}
res.json(team);
});
}
client.scenario.get('/v1/teams', (_req, res) => {
res.json({
teams,
});
});
return teams;
}