0
votes

can someone help me how can I pass error code and message to be able to parse it in a console for example...

in my case - if I don't set any status code it will return status code 200(even tho I use rules for validation) and I can see my custom message in the console logs console log with status code 200

but when I set 400 status code I get a generic message

public function store(StoreNewTeam $request)
    {
     $validator = Validator::make($request->all(),
            ['team.name' => 'required|unique:teams,name',
                'team.level' => 'required',
                'teamMembers.*.firstName' => 'required',
                'teamMembers.*.lastName' => 'required',
                'teamMembers.*.email' => 'required|unique:team_members,email',
                ]);

        if ($validator->fails()){
            return response()->json(['message' => $validator->errors()->first()],Response::HTTP_BAD_REQUEST);
        }

console log with status code 400 but when I go to network tab I can see my custom message...

how can I get that message to console?

and additional question... if I work on API like that is it OK to stay that way since I can see my message in network tab - as well in postman?

edit: StoreNewTeam is empty - just authorise is changed to true

since my request is array of 2 data combined I wanst able to type rules inside of StoreNewTeam

1
make custom request php artisan make:request and all validation there in rules - Salman Zafar
forgot to say I have already custom request, will upload name of the class - Night5talker
post that as well and also add your complete function - Salman Zafar
It's your browser (chrome?) console behavior depending on status. You should ask about it not in laravel category =) - Sergey Shuryakov
I found the reason why I see it... it was chrome... but my axios wasn't set up OK, will post answer just in case someone needs it in future - Night5talker

1 Answers

0
votes

so issue was not inside of laravel, but in my axios setup

to parse error in console axios error should be set up like this

.catch(function (error) {
   console.log(error.response);
 });