Proper way to return error from within a mutateAndGetPayload - relayjs

I am doing a number of business logic checks within the mutateAndGetPayload function of a relay mutation using the graphql-relay library. For any of these checks that fail I have an else clause that will throw an error, ig throw('You do not have permission to delete this resource');, however, when that happens, I get the error Cannot set property 'clientMutationId' of undefined returned to the frontend instead of the error I'm trying to return. It seems that I'm seeing this error because I'm not returning something this mutation cares about (or a promise that resolves to one), so I'm a little stumped ... what's the proper way to throw/return errors back to the client here?

One way is to use the GraphQLError Type
Working in NodeJS on the back end we have used the following library:
https://github.com/graphql/graphql-js/tree/master/src/error
However, what we have ended up using is a library that provides more flexibility:
https://github.com/kadirahq/graphql-errors
Either of these would be the best place to start.

Related

Google Adwords/Ads AdGroupAdService

I was wondering, if I add and delete some ads with the service AdGroupAdService, using the method mutate, If It returns me some errors ( not in all the operations i want to upload ), does it perfom correctly the others operations?
My initial guess was it does, but after a few checks, it does not.
So Am I missing something?
Thank you so much for your help
That is a feature known as partial failure.
If you set it to true within your SOAP header, then the program will run the operations that have no errors correctly.
If it is not set to true, then the whole program will fail if any operation has an error.

In py2neo, how do I know if a push() worked?

I'm updating a node and pushing it:
remote_graph.push(node)
push() seems to return nothing. How can I tell if the push works? In my test code, I ought to be violating a unique constraint in Neo4J.
How can I tell using py2neo? I expected an exception.
When I enter the equivalent cypher into the Neo4J web tool, I get the following exception:
Node 322184 already exists with label VERSION and property "version"=[1.436818928448956E9]
which is what I expected.
Edit -
What I expected to get back was an indicator of whether the operation worked or not. I think push() accepts an array of nodes, so an array of results would be sensible. I don't know what the indicator would have within it since I don't know what is available. An array of strings would be fine, with each string being a failure reason, or "OK".
Generally speaking, the design of this API is: if it returns OK, you can assume everything has worked as expected, if an error is raised, that error will contain details of what went wrong. Therefore, absence of error should usually be interpreted as a signal of success.
That said, if you believe that your push has failed and no error has been raised, there is a bug in py2neo. For debugging, you can check the state of the database after your push by using the browser and then if you're able to recreate this scenario in a standalone piece of code, please raise an issue on GitHub and I will be happy to fix it.

Capturing errors in Rust (Rust URL)

Please note I'm using a nightly build of Rust 0.13.0
First off, I'm a beginner to Rust and am still in the process of consuming as much information as possible on the language. Throughout my consumption the one topic I've been able to find very little on is error handling. So, when I first attempted to use an external library in my code I became quickly stumped at how I should be using the material being returned to me.
To help explain my confusion, I will be referencing the rust-url library. Here is some sample code found in the documentation:
use url::{Url, InvalidIpv6Address};
assert!(Url::parse("http://[:::1]") == Err(InvalidIpv6Address))
This is pretty straight-forward to me. However, my next question was: what about the other errors? I looked further into the ParseError enum and found 15+ other types of errors that could be potentially produced by a malformed URL.
So, my question is, what is considered the proper way to handle all of these various conditions? Should I have a lengthy match that alerts out specialized messages for each one? Is there a way to consume them all at once?
I apologize if there is not a single answer to this question, but Google was not making it clear and I would prefer to have feedback on this before I proceed coding the rest of my project the wrong way.
The ParseError enum implements the Show trait, with a custom useful message for each variant, so when you get to the final step of actually handling the parse error (e.g. after manipulating the Result in whatever ways you see fit), you can just treat the error possibilities as a black box:
fn download(s: &str) {
match Url::parse(s) {
Ok(url) => { ... }
Err(e) => {
println!("Could not parse '{}'. {}.", s, e);
}
}
}
will print things like Could not parse 'http://[:::1]'. Invalid IPv6 address..
(I filed #43 about making the Show message lower-cased, so that it flows better in more complicated error messages.)
Url::parse returns ParseResult<Url> which is defined as Result<Url, ParseError>, so you can make use of generic Result methods:
use url::{Url, InvalidIpv6Address};
assert!(Url::parse("http://[:::1]").is_err());
Result is Rust's preferred method for error handling, and has many convenience methods under the hood. For example, if you don't expect the failure you can use .unwrap() to make any failure fatal. When they don't suit your needs, you can also match against the Result.

Customizing All errors symfony 1.4

Sorry for my English and writing through a translator.
I'm new here and I'm a bit lost in what I want, maybe you can help me out if they wish, as explained here:
I want to customize all the errors that may be produced (any status code that is a mistake. 404, 500, 204, 301 .... etc.) And also show suggestions based on the "module" and/or "action" from where the error occurred.
I also wish I could tell by the file redirection "setting.yml" application, something like this:
error_404_module: common
error_404_action: errors
error_500_module: common
error_500_action: errors
error_204_module: common
error_204_action: errors
error_301_module: common
error_301_action: errors
........
Within the "app/frontend/modules/common" in the "action.class.php" define "executeErrors" in which I receive the status code that has occurred and the module where the error occurred or except for well, getting partial show "app/frontend/modules/common/templates/_errorXXXSuccess.php" and the partial of the suggestion that I seek and extract the module "referer" where the error occurred.
Well, that's the idea, dynamic content for different types of error in different circumstances and working perfectly with the type codes 404 but not with the rest ...
I read that could place me in the middle of the event by creating a file "config/error.html.php" and "config/exception.html.php". Indeed if I produce such a 500 error and manually these files are executed. The problem is that from there I can not access variables from symfony. Because if so I could invoke "common/errors" and bad send as parameters the error status code and the module where it occurred, but it is not. From there all I can do is play with $ _SERVER and routing.yml but can not get good results because the environment is mixed with Development Production (/frontend_dev.php) and is something I also want to avoid.
That is, I want to get as in "setting.yml" does "error_404_module" and "error_404_action" but with different error codes. Thus allowing me to show my custom pages in production based on "error or exception" and/or "module or action" where the error has been released from production, and in case of being in development mode (/frontend_dev.php/....), show the symfony Dispatch.
Surely life is complicandome and has a simpler way to do what I want but after thousands of combinations do not get the right result. Even if symfony may not allow other types of error redirect from "setting.yml" is because they are reserved for him or something. I do not understand.
Please please help me because no documentation to find and secure here at least we left public for others who want to do something.
Many Thanks and greetings!
First of all - you can't get symfony to intercept all errors. Some of the errors may be server errors and the request won't even get to your application. You can reproduce some of them explicitly setting responses in symfony though, but I may not be necessary to deal with all of them.
As for the exact response: you should use a listener to hook your errors to a class that handles them according to your need. See: https://stackoverflow.com/a/7077818/580167 for implementation details.

Custom Error handling in ASP MVC

I want to go beyond the default error handling given in ASP mvc. I have an errors controller, so I can hopefully give different error messages according to whats happened: i.e Invalid arguments, Permission denied, OMG DATABASE DEAD, etc.
But I cant seem to work out how to do this, this is what I have tried:
[HandleError(View="/Errors/InvalidArgument",ExceptionType=typeof(ArgumentException))]
It ends up giving a Runtime Error.
Also, on the same subject, is it possible to add more parameters that I could pass to the error controller, such as:
[HandleError(View="/Errors/InvalidArgument",ExceptionType=typeof(ArgumentException), Error="dumb arguments")]
Thanks
Just specify the View name, not it's path...as for passing arguments, I don't think you can.

Resources