app/Exceptions/Handler.php
/**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
Render an exception into an HTTP response.
Render an exception into an HTTP response .
public function render($request, Exception $e)
    {
        if($request->wantsJson() || $request->is('api/*')) {
            $json = [
                'success' => false,
                'error' => [
                    'code' => $e->getCode(),
                    'message' => $e->getMessage(),
                ],
            ];
            if($e instanceof ValidationException) $json['error']['errors'] = $e->errors();
            if($e instanceof ModelNotFoundException) {
                $json['error'] = [
                    'code' => 404,
                    'message' => __('apiMsg.applicant_not_found'),
                ];
            }
            return response()->json($json, 400); 
        }
        return parent::render($request, $e);
    }
public function render ( $ request , Exception $ e ) { if ( $ request -> wantsJson ( ) || $ request -> is ( 'api/*' ) ) { $ json = [ 'success' => false , 'error' => [ 'code' => $ e -> getCode ( ) , 'message' => $ e -> getMessage ( ) , ] , ] ; if ( $ e instanceof ValidationException ) $ json [ 'error' ] [ 'errors' ] = $ e -> errors ( ) ; if ( $ e instanceof ModelNotFoundException ) { $ json [ 'error' ] = [ 'code' => 404 , 'message' => __ ( 'apiMsg.applicant_not_found' ) , ] ; } return response ( ) -> json ( $ json , 400 ) ; } return parent :: render ( $ request , $ e ) ; }
Render an exception into an HTTP response.
Render an exception into an HTTP response .
//Handle Json Responses //general fail response format //add errors for validation //return 400 json response //return render response