Repository navigation
Conversation
| paths: ApiImpl.decodeResult(rawResult, completeRequest.elevation), | ||
| } | ||
| } else if (response.status !== 400) { | ||
| throw new Error(response.statusText) |
There was a problem hiding this comment.
The GraphHopper API returns 500 when a request times out, so when this happens we see `Internal Server Error' for example. Not sure if this is too unfriendly for users and what else we should do. Maybe 'Unexpected Error' or even 'The request timed out'? In most cases 500 should be because the request timed out and even when the reason was something else we could still show this message? And maybe log the actual error to the console?
| console.log(`route request failed, status: '${response.statusText}'`) | ||
| if (response.status === 500) | ||
| // not always true, but most of the time :) | ||
| throw new Error('Route calculation timed out') | ||
| throw new Error('Route request failed') |
There was a problem hiding this comment.
After thinking about this again I decided to use these more user-friendly error messages. WDYT? And should we translate the error messages (already?)
There was a problem hiding this comment.
Since we have translation now, I'd say yes, if we have an appropriate translation.
I find the different paths of the else if block not easy to read. isn't it somethig along the lines like
if (response.ok) {...}
else if (response.status === 500) {
throw new Error('Route calculation timed out')
} else if (response.status === 400) {
throw new Error('Insert your meaningful bad request message here')
} else {
console.log(`route request failed, status: '${response.statusText}'`)
throw new Error('Route request failed.')
}
There was a problem hiding this comment.
if we have an appropriate translation
Everyone can add translations here and we can use them now here too, yes :)
Add text to English at least (and maybe German) and prefix the key with web. and then run python3 update-translations.py.
There was a problem hiding this comment.
I cleaned up the if/else logic and added the translations (this worked right away 👍)
Janekdererste
left a comment
There was a problem hiding this comment.
Yes! Friendlier user messages.
| console.log(`route request failed, status: '${response.statusText}'`) | ||
| if (response.status === 500) | ||
| // not always true, but most of the time :) | ||
| throw new Error('Route calculation timed out') | ||
| throw new Error('Route request failed') |
There was a problem hiding this comment.
Since we have translation now, I'd say yes, if we have an appropriate translation.
I find the different paths of the else if block not easy to read. isn't it somethig along the lines like
if (response.ok) {...}
else if (response.status === 500) {
throw new Error('Route calculation timed out')
} else if (response.status === 400) {
throw new Error('Insert your meaningful bad request message here')
} else {
console.log(`route request failed, status: '${response.statusText}'`)
throw new Error('Route request failed.')
}
| } from '@/api/graphhopper' | ||
| import { LineString } from 'geojson' | ||
| import { getTranslation } from '@/translation/Translation' | ||
| const tr = getTranslation() |
There was a problem hiding this comment.
This is not ideal, because just loading the file executes getTranslation() and this fails if there was no setTranslation() before. Why do we even need getTranslation()? Can we not keep the Translation object local to Translation.ts and export only the tr function instead?
There was a problem hiding this comment.
Probably a good idea, yes. I played around and wasn't sure how to integrate this properly to make it convenient but also aligned to other code. My biggest problem with it is that this is a singleton but probably this is fine for a web app :)
There was a problem hiding this comment.
Can you take a look at my last commit to see if you like it?
There was a problem hiding this comment.
And what is your concern about the singleton? I think tr.json should only be loaded once (this data is global so to say). Other than that all we need is some handy access function to retrieve the data. We also need to keep some state to keep track which is the current language. This is handled by the Translation object currently and it makes sense there is only one such object?
There was a problem hiding this comment.
And what is your concern about the singleton?
I just dislike singletons in general (probably from my previous life as Android dev where it made everything a mess :D )
Can you take a look at my last commit to see if you like it?
Looks even more convenient, yes.
The mechanism is not really changed though. I.e. if setTranslation is not called before the usage you'll still get an error (?)
There was a problem hiding this comment.
The mechanism is not really changed though. I.e. if setTranslation is not called before the usage you'll still get an error
Yes. setTranslation still needs to be called before using it (makes sense). The problem was that we put const tr = getTranslation() at the beginning of some files. I did this because otherwise I would have to do getTranslation().get(..) wherever I wanted to translate something. But on the other hand if we put const tr = getTranslation at the beginning of the file this is executed as soon as the file is loaded and the order of the import statements becomes relevant which I thought was ugly.
|
Nice @easbar ! |
(cherry picked from commit 860318d)
Fixes #70
The issue is not strictly related to alternative routes, but whenever the GH API times out and we receive 500 our code failed because it was assuming there is a
hintsfield in the error response that we only get for 400 errors.