Open lilianjin opened 5 years ago
What's the full stacktrace?
@mfn I don't quite understand what you mean. The error message:
{"data":{"SignInMutation":null},"errors":[{"message":"Undefined index: mobile_phone","locations":[{"line":2,"column":3}]}]}
Undefined index
is a PHP runtime error. You need to figure out where it exactly occurred before anyone can assist you further. Hence I asked for a stacktrace.
I suggest you hook into \Folklore\GraphQL\GraphQL::formatError
or use a custom error formatter where you can investigate the actual exception and where it was thrown from.
@mfn Thank, I have solved the problem. In addition, I have another question. I expect the http status code to be 422 instead of 200 when the login form validation error. I expect to throw this exception.
You have to do this in your own.
The underlying webonxy library and to that extend this wrapper don't have specific support for this.
Also to consider: the "official" GraphQL spec from Facebook don't talk about status codes. At all.
My advice for clients/consumers is to almost forego the status code and just inspects the errors.*
payload (unless there's no payload at all).
OTOH, you can do what you want by:
graphql.error_formatter
(config setting)App\Exception\Handler
handle these cases and return what you wantMy solution was to do 1) and 2) (but not due to the status codes).
I do 1) because: especially for development, the errors returned from Folklore are a problem because they only contain the message but not the stacktrace. This slows down development immensely. I therefore use a custom formatter which does custom stuff but additionally calls into \GraphQL\Error\FormattedError::createFromException
and adds appropriate debug flags which can give you back traces.
It takes a bit tuning and learning to get this right but it pays off immediately IMHO.
@mfn Thank you very much for your help, I understand.
@mfn Thank, I have solved the problem. In addition, I have another question. I expect the http status code to be 422 instead of 200 when the login form validation error. I expect to throw this exception.
How did you fix it?
php
js
login