File tree Expand file tree Collapse file tree
pages/api/paybutton/transactions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { RESPONSE_MESSAGES } from 'constants/index'
22import { fetchTransactionsByPaybuttonId } from 'services/transactionService'
33import * as paybuttonService from 'services/paybuttonService'
44import { setSession } from 'utils/setSession'
5+ import { parseError } from 'utils/validators'
56
67export default async ( req : any , res : any ) : Promise < void > => {
78 if ( req . method === 'GET' ) {
@@ -19,14 +20,15 @@ export default async (req: any, res: any): Promise<void> => {
1920
2021 res . status ( 200 ) . json ( { transactions } )
2122 } catch ( err : any ) {
22- if ( err . message === RESPONSE_MESSAGES . NO_TRANSACTION_FOUND_404 . message ) {
23+ const parsedError = parseError ( err )
24+ if ( parsedError . message === RESPONSE_MESSAGES . NO_TRANSACTION_FOUND_404 . message ) {
2325 res . status ( RESPONSE_MESSAGES . NO_TRANSACTION_FOUND_404 . statusCode )
2426 . json ( RESPONSE_MESSAGES . NO_TRANSACTION_FOUND_404 )
25- } else if ( err . message === RESPONSE_MESSAGES . RESOURCE_DOES_NOT_BELONG_TO_USER_400 . message ) {
27+ } else if ( parsedError . message === RESPONSE_MESSAGES . RESOURCE_DOES_NOT_BELONG_TO_USER_400 . message ) {
2628 res . status ( RESPONSE_MESSAGES . RESOURCE_DOES_NOT_BELONG_TO_USER_400 . statusCode )
2729 . json ( RESPONSE_MESSAGES . RESOURCE_DOES_NOT_BELONG_TO_USER_400 )
2830 } else {
29- res . status ( 500 ) . json ( { statusCode : 500 , message : err . message } )
31+ res . status ( 500 ) . json ( { statusCode : 500 , message : parsedError . message } )
3032 }
3133 }
3234 } else {
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { fetchTxCountByPaybuttonId } from 'services/transactionService'
22import { RESPONSE_MESSAGES } from 'constants/index'
33import { fetchPaybuttonById } from 'services/paybuttonService'
44import { setSession } from 'utils/setSession'
5+ import { parseError } from 'utils/validators'
56
67export default async ( req : any , res : any ) : Promise < void > => {
78 if ( req . method === 'GET' ) {
@@ -16,7 +17,11 @@ export default async (req: any, res: any): Promise<void> => {
1617 const count = await fetchTxCountByPaybuttonId ( paybuttonId )
1718 res . status ( 200 ) . send ( count )
1819 } catch ( err : any ) {
19- switch ( err . message ) {
20+ const parsedError = parseError ( err )
21+ switch ( parsedError . message ) {
22+ case RESPONSE_MESSAGES . NO_BUTTON_FOUND_404 . message :
23+ res . status ( 404 ) . json ( RESPONSE_MESSAGES . NO_BUTTON_FOUND_404 )
24+ break
2025 case RESPONSE_MESSAGES . USER_ID_NOT_PROVIDED_400 . message :
2126 res . status ( 400 ) . json ( RESPONSE_MESSAGES . USER_ID_NOT_PROVIDED_400 )
2227 break
You can’t perform that action at this time.
0 commit comments