Skip to content

Empty sparse fieldset parameter returns 500 error #225

@mdpoulter

Description

@mdpoulter

When providing an empty value to any of the fields query parameters, the server returns a 500 error with server error being:

LaravelJsonApi\Validation\Rules\AllowedFieldSets::notAllowed(): Argument # 2 ($fields) must be of type string, null given, called in /vendor/laravel-json-api/validation/src/Rules/AllowedFieldSets.php on line 232"

For example, if the client requests the following:

http://localhost/api/v1/employees?fields[employees]=

It certainly makes sense for an error to be returned, but I would have expected a validation error given that this is a client issue. It also ends up in our error tracking software which isn't great.

While not an ideal solution, I wondered if adding validation for each of the fields parameters (current resource and all relations) would help. Unfortunately, it still returns the same 500 error for the above request. For example:

'fields' => [
    'nullable',
    'array',
    JsonApiRule::fieldSets(),
],
'fields.employees' => 'filled',

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy