fix self ai plan generation authorization and error handling
This commit is contained in:
parent
c877577fba
commit
73218402f6
@ -114,13 +114,6 @@ export async function POST() {
|
||||
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
if (currentUser.role !== "client") {
|
||||
return NextResponse.json(
|
||||
{ error: "Only clients can self-generate AI plans" },
|
||||
{ status: 403 },
|
||||
);
|
||||
}
|
||||
|
||||
const { membershipType, features } = await getUserMembershipContext(userId);
|
||||
|
||||
if (membershipType === "basic") {
|
||||
|
||||
@ -124,10 +124,20 @@ export async function generateSelfRecommendation(
|
||||
);
|
||||
return parseApiData<Recommendation>(response.data);
|
||||
} catch (error) {
|
||||
if (isAxiosError(error) && error.response) {
|
||||
throw new Error(
|
||||
`Failed to generate recommendation: ${error.response.status}`,
|
||||
);
|
||||
if (isAxiosError(error)) {
|
||||
const responseError = error.response?.data as
|
||||
| { error?: string }
|
||||
| undefined;
|
||||
|
||||
if (responseError?.error) {
|
||||
throw new Error(responseError.error);
|
||||
}
|
||||
|
||||
if (error.response) {
|
||||
throw new Error(
|
||||
`Failed to generate recommendation: ${error.response.status}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user