diff --git a/apps/api/src/maps/maps.service.ts b/apps/api/src/maps/maps.service.ts index c071092..4bb8a09 100644 --- a/apps/api/src/maps/maps.service.ts +++ b/apps/api/src/maps/maps.service.ts @@ -256,6 +256,33 @@ export class MapsService { alternatives: altRoutes }; } catch (error) { + if (error instanceof HttpException) { + throw error; + } + + const ghData = error.response?.data; + const rawMsg = ghData?.message || error.message || ''; + + // 1. Point Not Found (Outside coverage area or in water/remote off-road) + if (rawMsg.includes('Cannot find point') || rawMsg.includes('PointNotFoundException')) { + const pointMatch = rawMsg.match(/Cannot find point\s+(\d+):\s*([0-9.,]+)/i); + const pointIndex = pointMatch ? (Number(pointMatch[1]) + 1) : ''; + const pointCoords = pointMatch ? `[${pointMatch[2]}]` : ''; + + throw new HttpException( + `تعذر العثور على مسار: النقطة ${pointIndex ? `رقم ${pointIndex}` : ''} ${pointCoords} تقع خارج نطاق خريطة الأردن المعتمدة أو في منطقة حدودية/وعرة بعيدة عن شبكة الطرق المعبدة.`, + HttpStatus.UNPROCESSABLE_ENTITY + ); + } + + // 2. No connection between locations (e.g. islands, separated networks) + if (rawMsg.includes('Connection between locations not found')) { + throw new HttpException( + 'لا يوجد مسار أو شبكة طرق معبدة متصلة تربط بين نقطة الانطلاق والوجهة المحددة.', + HttpStatus.UNPROCESSABLE_ENTITY + ); + } + const msg = error.response ? `GH Error: ${JSON.stringify(error.response.data)}` : `DNS/Connection Error: ${error.message}`; console.error('CRITICAL ROUTING FAILURE:', msg); throw new HttpException(`Routing Failure: ${msg}`, HttpStatus.BAD_GATEWAY);