cardanoapi / mempool-explorer

Cardano Mempool Explorer
https://mempool.cardanoapi.io
Apache License 2.0
3 stars 2 forks source link

Handle DTO's undefined and client-side exception #3

Open bibishan-pandey opened 6 months ago

bibishan-pandey commented 6 months ago

This issue is not always reproducible, but the data coming in from the API or the real-time data from the WebSocket is sometimes undefined inside the object itself, which needs to be correctly handled in the interface for the DTOs in the TypeScript.

What I mean by that is we have some DTOs that look like this:

export interface FollowupBodyType {
    auxiliary_data_hash: string;
    certs: string | undefined;
    collateral: Array<any>;
    collateral_return: Object;
    fee: string;
    inputs: Array<InputTypes>;
    mint: Array<any>;
    network_id: string | undefined;
    outputs: Array<OutputTypes>;
    reference_inputs: Array<any> | undefined;
    required_signers: Array<any> | undefined;
    script_data_hash: string;
    total_collateral: string;
    ttl: string;
    update: undefined | boolean;
    validity_start_interval: undefined | string;
    withdrawals: any;
    is_valid: boolean;
    witness_set: any;
}

If we look closely, collateral_return: Object; this property expects the Object as its data type, and we can have anything inside this. So, these interface and property data types might likely be the root cause for these exceptions.

Solution