File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -8,8 +8,13 @@ export const GET = async (req: Request) => {
88
99 return NextResponse . json ( { message : 'OK' , posts } , { status : 200 } ) ;
1010 } catch ( err ) {
11- return NextResponse . json ( { message : 'Error' , err : err . message } , { status : 500 } ) ;
11+ if ( err instanceof Error ) {
12+ return NextResponse . json ( { message : 'Error' , err : err . message } , { status : 500 } ) ;
13+ } else {
14+ return NextResponse . json ( { message : 'Unknown error' } , { status : 500 } ) ;
15+ }
1216 }
17+
1318}
1419
1520export const POST = async ( req : Request ) => {
@@ -20,6 +25,11 @@ export const POST = async (req: Request) => {
2025 await addPost ( post ) ; // Garantir que a função addPost aguarde a inserção do post
2126 return NextResponse . json ( { message : "Ok" , post } , { status : 201 } ) ;
2227 } catch ( err ) {
23- return NextResponse . json ( { message : 'Error' , err : err . message } , { status : 500 } ) ;
28+ if ( err instanceof Error ) {
29+ return NextResponse . json ( { message : 'Error' , err : err . message } , { status : 500 } ) ;
30+ } else {
31+ return NextResponse . json ( { message : 'Unknown error' } , { status : 500 } ) ;
32+ }
2433 }
34+
2535}
You can’t perform that action at this time.
0 commit comments