Better API errors

This commit is contained in:
Daniel Walsh 2023-05-21 09:36:23 +01:00
parent 46e7ceca56
commit fd5884de2a
No known key found for this signature in database
2 changed files with 20 additions and 3 deletions

View file

@ -22075,7 +22075,16 @@ try {
`https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}`, `https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}`,
{ headers: { Authorization: `Bearer ${apiToken}` } } { headers: { Authorization: `Bearer ${apiToken}` } }
); );
if (response.status !== 200) {
console.error(`Cloudflare API returned non-200: ${response.status}`);
const json = await response.text();
console.error(`API returned: ${json}`);
throw new Error("Failed to get Pages project, API returned non-200");
}
const { result } = await response.json(); const { result } = await response.json();
if (result === null) {
throw new Error("Failed to get Pages project, project does not exist. Check the project name or create it!");
}
return result; return result;
}; };
const createPagesDeployment = async () => { const createPagesDeployment = async () => {
@ -22156,8 +22165,6 @@ try {
}; };
(async () => { (async () => {
const project = await getProject(); const project = await getProject();
if (!project)
throw new Error("Unable to find pages project");
const productionEnvironment = githubBranch === project.production_branch || branch === project.production_branch; const productionEnvironment = githubBranch === project.production_branch || branch === project.production_branch;
const environmentName = `${projectName} (${productionEnvironment ? "Production" : "Preview"})`; const environmentName = `${projectName} (${productionEnvironment ? "Production" : "Preview"})`;
let gitHubDeployment; let gitHubDeployment;

View file

@ -23,7 +23,18 @@ try {
`https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}`, `https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}`,
{ headers: { Authorization: `Bearer ${apiToken}` } } { headers: { Authorization: `Bearer ${apiToken}` } }
); );
if (response.status !== 200) {
console.error(`Cloudflare API returned non-200: ${response.status}`);
const json = await response.text();
console.error(`API returned: ${json}`);
throw new Error("Failed to get Pages project, API returned non-200");
}
const { result } = (await response.json()) as { result: Project | null }; const { result } = (await response.json()) as { result: Project | null };
if (result === null) {
throw new Error("Failed to get Pages project, project does not exist. Check the project name or create it!");
}
return result; return result;
}; };
@ -126,7 +137,6 @@ try {
(async () => { (async () => {
const project = await getProject(); const project = await getProject();
if (!project) throw new Error("Unable to find pages project");
const productionEnvironment = githubBranch === project.production_branch || branch === project.production_branch; const productionEnvironment = githubBranch === project.production_branch || branch === project.production_branch;
const environmentName = `${projectName} (${productionEnvironment ? "Production" : "Preview"})`; const environmentName = `${projectName} (${productionEnvironment ? "Production" : "Preview"})`;