Skip to content

Commit

Permalink
feat: Add more informative error message newUserFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
topher-lo committed Jun 5, 2024
1 parent f653bae commit 2744f57
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions frontend/src/lib/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,28 @@ import { client } from "@/lib/api"
* Initialize user settings in the database
* @returns void
*/

export async function newUserFlow(): Promise<void> {
console.log("Start new user flow")
console.log("Start new user flow");

try {
const response = await client.put("/users")
const response = await client.put("/users");
if (response.status !== 201) {
throw new Error("Unexpected response status")
throw new Error("Unexpected response status");
}
console.log("New user created")
console.log("New user created");
} catch (e) {
if (e instanceof AxiosError) {
if (e.response?.status !== 409) {
throw new Error("Error creating new user")
if (process.env.TRACECAT__APP_ENV !== "production") {
throw new Error("Internal Server Error. Please check API service logs to debug.");
} else {
throw new Error("Unexpected error creating new user in production. Try running in development mode for more detailed error logs.");
}
}
console.log("User already exists")
console.log("User already exists");
} else {
throw e; // Re-throw non-Axios errors
}
}
}
Expand Down

0 comments on commit 2744f57

Please sign in to comment.