-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better error handling #21
Comments
This sounds like a good idea. However, I'd like to really understand your use case and the requirements here. Could you paste a code snippet of the part where you are using traverson/traverson-hal. You probably have some kind of if statement that does different things depending on the kind of error, I would like to see that, if possible. |
Hey. It is taken form Traverson Readme traverson
.from('http://api.io')
.jsonHal()
.follow('ht:me', 'ht:posts')
.getResource(function(error, document) {
if (error) {
console.error(error.name)
}
}); I can get error type - which is I've also tried traverson
.from('http://haltalk.herokuapp.com/')
.jsonHal()
.follow('ht:me')
.getResource(function(error, document) {
if (error) {
console.log(error.name);
}
});
The problem is with traverson
.from('http://api.opensupporter.org/api/v1/')
.jsonHal()
.follow('self', 'invalid_link')
.getResource(function(error, document) {
if (error) {
console.log(error.name);
}
});
I would like to know what type of error it is. (like linkMissing), and some other errors for |
Thanks for the code snippets. That's not exactly what I meant, though. What I am interested in is what you are going to do, depending on various error types. How does you code handle these different errors? You surely do not want to differentiate between them just to call |
Sure.
|
@basti1302 Should I prepare PR for that? |
Yes, that would be welcome! |
@basti1302 |
Sure, I'll probably can get it done tomorrow. A little more patience :) |
Thanks for merging. |
This has been released with version 5.0.0. |
From the release notes, for reference: All |
Btw, thanks for the PR over in #22 and bringing the issue up in general. After merging your changes I extended them to the whole codebase. You might want to check out this commit in traverson-hal and this commit in traverson to see if it still fits your requirements (it should, I think). Also, this comment might be relevant for your use case (depends on your hal documents). |
I am using traverson for a while.
Recently I've noticed that there is no way to detect if error during request is from traverson or traverson-hal. Moreover it returns only plain message, without any error type.
Like in https://github.com/basti1302/traverson-hal/blob/master/index.js#L64
I need to know if its a
linkError
orembeddedError
(For example link to resource is not in server response)Currently I can only parse strings, but it would be much more convenient to get error type, either by
create own
Error
types,pass to
Error
object instead stringor just add
ctx
as 2nd argument ofError
The text was updated successfully, but these errors were encountered: