Coder Social home page Coder Social logo

Comments (8)

dragonfire1119 avatar dragonfire1119 commented on June 15, 2024 1

I made a temporary fix until you investigate a solution.

if ($request->expectsJson())
{
    if($e instanceof ValidationException) {
        $errors = $e->validator->errors();
        return ResponseBuilder::errorWithMessageAndData(ErrorCode::VALIDATION_ERROR, 'Validation errors', [
            'message' => $errors->first(),
            'messages' => $errors->getMessages(),
        ]);
    } else if($e instanceof AuthorizationException) {
        return ResponseBuilder::errorWithHttpCode(ErrorCode::UNAUTHORIZED, ErrorCode::UNAUTHORIZED);
    }
    return ExceptionHandlerHelper::render($request, $e);
}

from laravel-api-response-builder.

MarcinOrlowski avatar MarcinOrlowski commented on June 15, 2024 1

It seems I need to update Exception Handler helper code as it is not fully compatible with recent Laravel. AFAIR it sticks to 5.2 flow, yet there are changes in recent Laravel that remain uncovered. IT will be addressed in next release.

Thanks for the feedback. Keep it coming.

from laravel-api-response-builder.

MarcinOrlowski avatar MarcinOrlowski commented on June 15, 2024

First, you need to check your server's error.log.

from laravel-api-response-builder.

dragonfire1119 avatar dragonfire1119 commented on June 15, 2024

@MarcinOrlowski Ok you didn't understand the laravel api response works just it doesn't work/use the FormRequest. It's throwing a Illuminate\\Validation\\ValidationException but api response is not handling it right.

The message just says this "message": "The given data failed to pass validation.", that doesn't tell you what fields failed the validation?

Right now I'm using it the bloated way.

        $validator = Validator::make($request->all(), [
		'name' => 'required|max:191',
        ]);

	if ($validator->fails()) {
            return ResponseBuilder::errorWithMessageAndData(ErrorCode::VALIDATION_ERROR, 'Validation errors', [
                'message' => $validator->messages()->first(),
                'messages' => $validator->messages(),
            ]);
        }

Which is allot of code that the FormRequest can resolve.

from laravel-api-response-builder.

dragonfire1119 avatar dragonfire1119 commented on June 15, 2024

Ok this is another situation where your custom exception handler doesn't check if it's a instanceof ValidationException.

https://github.com/laravel/framework/blob/5.4/src/Illuminate/Foundation/Exceptions/Handler.php#L115

from laravel-api-response-builder.

MarcinOrlowski avatar MarcinOrlowski commented on June 15, 2024

What version of Laravel you use?

from laravel-api-response-builder.

dragonfire1119 avatar dragonfire1119 commented on June 15, 2024

@MarcinOrlowski This current project is using 5.4

from laravel-api-response-builder.

MarcinOrlowski avatar MarcinOrlowski commented on June 15, 2024

Added in @dev

from laravel-api-response-builder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.