Skip to content

Commit

Permalink
Return error messages to client
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneIRL committed Oct 6, 2023
1 parent 55ad3f7 commit a607ac3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/app/admin/role/[roles]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import clientPromise from '@/lib/db'
import { AppPermissionsSchema, Role } from '@/lib/db/models/Role'
import User from '@/lib/db/models/User'
import logger from '@/lib/logger'
import { stringifyError } from '@/lib/utils/shared'
import { NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'

Expand Down Expand Up @@ -35,7 +36,7 @@ export async function DELETE(
return NextResponse.json({ status: 'success' })
} catch (e) {
logger.error(e, req.nextUrl.toString())
return NextResponse.json({ status: 'error' })
return NextResponse.json({ status: 'error', message: stringifyError(e) })
}
}

Expand All @@ -57,7 +58,7 @@ export async function POST(
return NextResponse.json({ status: 'success' })
} catch (e) {
logger.error(e, req.nextUrl.toString())
return NextResponse.json({ status: 'error' })
return NextResponse.json({ status: 'error', message: stringifyError(e) })
}
}

Expand Down Expand Up @@ -87,6 +88,6 @@ export async function PUT(
return NextResponse.json({ status: 'success' })
} catch (e) {
logger.error(e, req.nextUrl.toString())
return NextResponse.json({ status: 'error' })
return NextResponse.json({ status: 'error', message: stringifyError(e) })
}
}
4 changes: 2 additions & 2 deletions src/app/admin/role/[roles]/view-as/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clientPromise from '@/lib/db'
import User from '@/lib/db/models/User'
import logger from '@/lib/logger'
import { getEnhancedSession } from '@/lib/utils/server'
import { getEnhancedSession, stringifyError } from '@/lib/utils/server'
import { ObjectId } from 'mongodb'
import { headers } from 'next/headers'
import { NextRequest, NextResponse } from 'next/server'
Expand Down Expand Up @@ -49,6 +49,6 @@ export async function POST(
return NextResponse.json({ status: 'success' })
} catch (e) {
logger.error(e, req.nextUrl.toString())
return NextResponse.json({ status: 'error' })
return NextResponse.json({ status: 'error', message: stringifyError(e) })
}
}

0 comments on commit a607ac3

Please sign in to comment.