import { ResponseData } from "../FlutterwaveInit" ; import FlutterwaveInitError from "./FlutterwaveInitError" ; param message param code returns { message export default function ResponseParser ( { status , errors , message , data , code , error_id , } ) { return new Promise ( ( resolve , reject ) => { if ( status === 'success' ) { if ( ! data || ! data . link ) { return reject ( new FlutterwaveInitError ( { code : 'MALFORMED_RESPONSE' , message } ) ) ; } return resolve ( data . link ) ; } if ( /authorization/i . test ( message ) && /required/i . test ( message ) ) { reject ( new FlutterwaveInitError ( { code : 'AUTH_MISSING' , message } ) ) ; } if ( /authorization/i . test ( message ) && /invalid/i . test ( message ) ) { reject ( new FlutterwaveInitError ( { code : 'AUTH_INVALID' , message } ) ) ; } if ( errors ) { reject ( new FlutterwaveInitError ( { code : 'INVALID_OPTIONS' , message : message , errors : errors . map ( i => i . message ) } ) ) ; } reject ( new FlutterwaveInitError ( { code : String ( code || 'STANDARD_INIT_ERROR' ) . toUpperCase ( ) , message , errorId : error_id } ) ) ; } ) ; }