@@ -10,7 +10,7 @@ async function handler(req, res) {
1010 try {
1111 body = JSON . parse ( req . body ) ;
1212 } catch {
13- return res . status ( 400 ) . send ( {
13+ return res . status ( 400 ) . json ( {
1414 message : 'Invalid JSON body' ,
1515 } ) ;
1616 }
@@ -24,8 +24,8 @@ async function handler(req, res) {
2424 * POST HANDLER
2525 */
2626 if ( ! body . email ) {
27- return res . status ( 400 ) . send ( {
28- " message" : 'email is required'
27+ return res . status ( 400 ) . json ( {
28+ message : 'email is required' ,
2929 } ) ;
3030 }
3131
@@ -36,17 +36,17 @@ async function handler(req, res) {
3636 } ;
3737 await profileCollection . insert ( profile . pid , profile )
3838 . then ( ( result ) => {
39- res . status ( 201 ) . send ( { ...profile , ...result } ) ;
39+ res . status ( 201 ) . json ( { ...profile , ...result } ) ;
4040 } )
4141 . catch ( ( error ) => {
4242 if ( error . message === 'authentication failure' ) {
43- return res . status ( 401 ) . send ( {
44- " message" : error . message ,
43+ return res . status ( 401 ) . json ( {
44+ message : error . message ,
4545 } ) ;
4646 }
4747
48- res . status ( 500 ) . send ( {
49- " message" : `Profile Insert Failed: ${ error . message } `
48+ res . status ( 500 ) . json ( {
49+ message : `Profile Insert Failed: ${ error . message } ` ,
5050 } ) ;
5151 } ) ;
5252 } else if ( req . method === 'PUT' ) {
@@ -67,19 +67,21 @@ async function handler(req, res) {
6767
6868 /* Persist updates with new doc */
6969 await profileCollection . upsert ( req . query . pid , newDoc )
70- . then ( ( result ) => res . send ( { ...newDoc , ...result } ) )
70+ . then ( ( result ) => res . json ( { ...newDoc , ...result } ) )
7171 . catch ( ( error ) => {
7272 if ( error . message === 'authentication failure' ) {
73- return res . status ( 401 ) . send ( {
74- " message" : error . message ,
73+ return res . status ( 401 ) . json ( {
74+ message : error . message ,
7575 } ) ;
7676 }
7777
78- res . status ( 500 ) . send ( error ) ;
78+ res . status ( 500 ) . json ( {
79+ message : error . message ,
80+ } ) ;
7981 } ) ;
8082 } )
81- . catch ( ( e ) => res . status ( 500 ) . send ( {
82- " message" : `Profile Not Found, cannot update: ${ e . message } `
83+ . catch ( ( e ) => res . status ( 500 ) . json ( {
84+ message : `Profile Not Found, cannot update: ${ e . message } ` ,
8385 } ) ) ;
8486 } catch ( e ) {
8587 console . error ( e ) ;
@@ -111,9 +113,9 @@ async function handler(req, res) {
111113 LIMIT $LIMIT OFFSET $SKIP;
112114 ` ;
113115 await cluster . query ( query , options )
114- . then ( ( result ) => res . send ( result . rows ) )
115- . catch ( ( error ) => res . status ( 500 ) . send ( {
116- " message" : `Query failed: ${ error . message } `
116+ . then ( ( result ) => res . json ( result . rows ) )
117+ . catch ( ( error ) => res . status ( 500 ) . json ( {
118+ message : `Query failed: ${ error . message } ` ,
117119 } ) ) ;
118120 } catch ( e ) {
119121 console . error ( e ) ;
@@ -125,17 +127,17 @@ async function handler(req, res) {
125127 try {
126128 await profileCollection . remove ( req . query . pid )
127129 . then ( ( ) => {
128- res . status ( 200 ) . send ( { message : " Successfully Deleted: " + req . query . pid } ) ;
130+ res . status ( 200 ) . json ( { message : ` Successfully Deleted: ${ req . query . pid } ` } ) ;
129131 } )
130132 . catch ( ( error ) => {
131133 if ( error . message === 'authentication failure' ) {
132- return res . status ( 401 ) . send ( {
133- " message" : error . message ,
134+ return res . status ( 401 ) . json ( {
135+ message : error . message ,
134136 } ) ;
135137 }
136138
137- res . status ( 500 ) . send ( {
138- " message" : `Profile Not Found, cannot delete: ${ error . message } `
139+ res . status ( 500 ) . json ( {
140+ message : `Profile Not Found, cannot delete: ${ error . message } ` ,
139141 } ) ;
140142 } ) ;
141143 } catch ( e ) {
0 commit comments