Menu

1 / 2

Domain exceptions between NestJS and React: an identifier with data, not a sentence

DEV Community: react·Hector Angel Gomez Robaina·12 days ago
#foUglJ44
#devtoreact#devto#dev#error#shipment
Reading 0:00
15s threshold

This is how the client of this API dispatches a shipment:

// client/src/modules/shipment/services/dispatch-shipment.ts import { instance } from " @modules/app/modules/http/domain/instance " ; import { DispatchShipmentDTO } from " ../dto/write/dispatch-shipment " ;

export async function dispatchShipment ( props : DispatchShipmentDTO , ): Promise < boolean > { try { await instance . post ( " /shipments/dispatch " , props );

return true ; } catch { return false ; } }

Enter fullscreen mode

Exit fullscreen mode

And this is how it is consumed, in the button component:

// client/src/modules/shipment/components/DispatchButton/hooks/useDispatchButton.tsx const dispatched = await dispatchShipment ({ shipmentId , carrierId });

if ( ! dispatched ) { toastError ({ en : " The shipment could not be dispatched. " , es : " No se pudo despachar el envío. " , }); }

Enter fullscreen mode

Exit fullscreen mode

This code is not a bug, and reviewed on its own there is nothing to fix.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.