fix(routing): Friendly Arabic diagnostic messages for out-of-boundary / off-grid points

This commit is contained in:
Hamza-Ayed
2026-08-21 02:26:38 +03:00
parent 0849b7b53c
commit 398daceffb
+27
View File
@@ -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);