vendredi 30 novembre 2018

Laravel 5.7 Response Status Code Always Returns 200 Even For 422 Errors

I am stuck with a major issue. I have being developing a application for a while. I had set some responses to send the 422 response error code which was initially working fine, but I recently tested those modules again and now those responses only send a 200 status. I tried setting different status codes and it is always sending 200 status code. I have used request->validate to validate the file type, this also sends a 200 status code in error situations. I checked my current status with my GIT commits and I couldn't find any instance that shows a modification that impedes this. Would really appreciate some help regarding this. I am too far off to roll back to the working state.

My Code That should send a different status code instead of 200

$validated = $request->validate(['inputFile' => 'required|mimes:xlsx,xls']);
    if($validated){
        $exists = DB::table($this->tables['tblperiod'][0])->where([[ $this->tables[ 'tblperiod'][1][1], $request->month ],[ $this->tables['tblperiod'][1][2], $request->year ]])->exists();
        if(!$exists){
            $this->doExcel($request);
            $uploadData = $this->getRecentUpload($this->tables['tblallocation'][0], $this->tables['tblallocation'][1], $this->tables['tblperiod'][0], $this->tables['tblperiod'][1], $request->month, $request->year);
            return response()->json(['success' => 'Data set of '. $request->month .' '. $request->year .' has been successfully imported and ready for reports.', 'upload' => $uploadData, 'month' => $request->month, 'year' => $request->year]);
        }else{
            return response()->json(['errors' => 'The data set ('. $request->month .' '. $request->year .') you are trying to upload already exists! Please check the period and try again.'], 422);
        }
    }



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2AIKhh4
via IFTTT

Aucun commentaire:

Enregistrer un commentaire