Skip to content

Bug: "Type is not supported" in Postgresql POST restful #2812

Description

@samsonasik

I tried to create a restful api with POST data for create products and call:

 curl -i -X POST -d "product_code=A1114&product_name=Corn" http://ci4.local/products

and got the following errors:

HTTP/1.1 500 Internal Server Error
Date: Thu, 09 Apr 2020 01:13:21 GMT
Server: Apache/2.4.41 (Unix) PHP/7.4.4
X-Powered-By: PHP/7.4.4
Cache-control: no-store, max-age=0, no-cache
Content-Length: 2568
Connection: close
Content-Type: application/json; charset=UTF-8

<br />
<b>Fatal error</b>:  Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse json string, error: &quot;Type is not supported&quot;. in /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Format/Exceptions/FormatException.php:9
Stack trace:
#0 /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Format/JSONFormatter.php(67): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/API/ResponseTrait.php(401): CodeIgniter\Format\JSONFormatter-&gt;format(Array)
#2 /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/API/ResponseTrait.php(131): CodeIgniter\Debug\Exceptions-&gt;format(Array)
#3 /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Debug/Exceptions.php(165): CodeIgniter\Debug\Exceptions-&gt;respond(Array, 500)
#4 [internal function]: CodeIgniter\Debug\Exceptions-&gt;exceptionHandler(Object(ErrorException))
#5 {main}
  thrown in <b>/Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Format/Exceptions/FormatException.php</b> on line <b>9</b><br />
{
    "title": "ErrorException",
    "type": "ErrorException",
    "code": 500,
    "message": "Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse json string, error: \"Type is not supported\". in /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Format/Exceptions/FormatException.php:9\nStack trace:\n#0 /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Format/JSONFormatter.php(67): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON('Type is not sup...')\n#1 /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/API/ResponseTrait.php(401): CodeIgniter\\Format\\JSONFormatter->format(Array)\n#2 /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/API/ResponseTrait.php(131): CodeIgniter\\Debug\\Exceptions->format(Array)\n#3 /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Debug/Exceptions.php(165): CodeIgniter\\Debug\\Exceptions->respond(Array, 500)\n#4 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(ErrorException))\n#5 {main}\n  thrown",
    "file": "/Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Format/Exceptions/FormatException.php",
    "line": 9,
    "trace": [
        {
            "function": "shutdownHandler",
            "class": "CodeIgniter\\Debug\\Exceptions",
            "type": "->",
            "args": []
        }
    ]
}%                                                   

My controller is like the following:

<?php namespace App\Controllers;

use CodeIgniter\RESTful\ResourceController;

class Products extends ResourceController
{
    protected $modelName = 'App\Models\ProductModel';
    protected $format    = 'json';

    public function create()
    {
        $data = $this->request->getPost();

        if (! $this->model->save($data))
        {
            return $this->respond($this->model->errors());

        }

        return $this->respondCreated($data, 'product created');
    }
}

I switched to mysql and it is working fine.

CodeIgniter 4 version
latest dev-develop

Affected module(s)
Database

Expected behavior, and steps to reproduce if appropriate
should be working

Context

  • OS: macOS Sierra
  • Web server Apache
  • PHP version 7.4.4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions