Skip to content

Commit

Permalink
Adds input validation to device group creation
Browse files Browse the repository at this point in the history
  • Loading branch information
gruyaume committed Dec 7, 2023
1 parent 1e1c430 commit 0f9f432
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pages/api/device-group/[name].ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ async function handleGET(req: NextApiRequest, res: NextApiResponse) {
});

if (!response.ok) {
throw new Error(`Error getting device group. Error code: ${response.status}`);
res.status(response.status).json({ error: "Error retrieving network slice." });
return;
}

const data = await response.json();
Expand Down
2 changes: 1 addition & 1 deletion pages/api/network-slice/[name].ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function handleGET(req: NextApiRequest, res: NextApiResponse) {


if (!response.ok) {
res.status(response.status).json({ error: "Invalid name provided." });
res.status(response.status).json({ error: "Error retrieving network slice." });
return;
}

Expand Down
11 changes: 11 additions & 0 deletions utils/createDeviceGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ export const createDeviceGroup = async ({
};

try {
const checkResponse = await fetch(`/api/device-group/${name}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});

if (checkResponse.ok) {
throw new Error("Device group already exists");
}

const response = await fetch(`/api/device-group/${name}`, {
method: "POST",
headers: {
Expand Down

0 comments on commit 0f9f432

Please sign in to comment.