-
Notifications
You must be signed in to change notification settings - Fork 323
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
How to have access to UploadApiErrorResponse to handle cloudinary errors? #449
Comments
Hi @manoellribeiro , for any error in upload, it will be pass in the cloudinary.uploader.upload("my_picture.jpg", function(error, result) {
console.log(result);
console.error(error);
}); |
Hi @leptians, thanks for your answer. I read about that in the docs, but I think it throws that error object as well, as I'm using it inside a try...catch block I would like to handle in the catch block not in the callback function.
|
@manoellribeiro cloudinary.uploader.upload("my_picture.jpg", function(error, result) {
if (typeof error !== 'undefined') {
throw .... // Throw the type of error and message of your choice.
}
}); |
@manoellribeiro , thanks for sharing the link and that makes sense. |
@leptians
I don't have much experience with Javascript, so maybe I'm not using best practices as you said (I'm open for tips). But I was only trying to check the error object type that is thrown when the upload fails. |
Hi @manoellribeiro , the parent function where you have Cloudinary uploader is async, however I would still recommend to handle your error inside the callback, and this is common practice for an async operation: cloudinary.uploader.upload("my_picture.jpg", function(error, result) {
if (typeof error !== 'undefined') {
// handle errors
}
}); if you can share more detail on this If you don't feel comfortable sharing the code publicly, you can open a ticket with this detail via our support portal (https://support.cloudinary.com/hc/en-us/requests/new) and we can continue from there. |
@leptians Thank you for the help, but I have already found a way to handle it, so I think it won't be needed and I'm closing this issue as it seems to be a duplicated of #131. I don't know if it is a best practice or not, but I did this way, if someone else come here with the same doubt:
As @leptians mentioned I could also do that:
As I'm trying to keep a pattern in my application I used the first way, but the second worked just fine as well. |
I'm trying to handle errors from the upload method, so I want to have access to the interface UploadApiErrorResponse to check if the thrown errors is from cloudinary or not. Is there a way I can do that?
For example, with Sequelize you can do:
The text was updated successfully, but these errors were encountered: