Open dmiluski opened 3 years ago
This message comes from the Directions API. In some cases, this library does use other fields in the error JSON or HTTP headers to compose its own localizable error message. Unfortunately, in the case of a request like https://api.mapbox.com/directions/v5/mapbox/driving-traffic/-146.95,61.61;-70.66,-46.32.json?overview=false&steps=true&access_token=pk.…
, the response contains just this body with no machine-readable distance in the JSON or HTTP headers:
{"message":"Total distance between all coordinates cannot exceed 10000km","code":"InvalidInput"}
In fact, the library doesn’t even know that it’s a too-long error because that information isn’t communicated to the client. In theory, we could parse the message
for this sentence and convert the distance ourselves, but that would introduce a tight coupling to a detail of the API that may change without notice.
/cc @mapbox/navigation-api
To provide better feedback to our users, we are using DirectionError to display actionable feedback to users when they have created a route that is not routable.
Unfortunately, this uses a static string to display content which assumes km. On searching GitHub, I haven't been able to find the source of this text, so assuming it is being returned
invalidInput(message: Optional("Total distance between all coordinates cannot exceed 10000km"))
Ideally, we would either be able to:
Given the result appears to represent any input error, it's unlikely an app could perform this inference alone.