mixerapi / mixerapi-dev Goto Github PK
View Code? Open in Web Editor NEWDevelopment (monorepo) repository for MixerAPI
Home Page: https://mixerapi.com
License: MIT License
Development (monorepo) repository for MixerAPI
Home Page: https://mixerapi.com
License: MIT License
What Happened
First off, not sure if this is an actual defect or if I'm throwing exceptions incorrectly. Feel free to let me know if it's the latter.
My tests broke as of Mixer 1.1.6 and I noticed the bugfix (#128) involving the $exceptions
property in the exceptions renderer, here is the specific test failure I'm encountering:
✘ Authenticate rejects invalid base 64 encoded payloads
┐
├ Failed asserting that two strings are equal.
┊ ---·Expected
┊ +++·Actual
┊ @@ @@
┊ -'{"exception":"BadRequestException","message":"<error message>","url":"\/users\/authenticate","code":400}'
┊ +'{"exception":"BadRequestException","message":"<error message>","url":"\/users\/authenticate","code":400,"exceptions":[{}]}'
│
╵ /Users/path/to/my/Code/tests/TestCase/Controller/UsersControllerTest.php:165
┴
Note the EMPTY exceptions
property in the rendered exception. Here's the test that throws this error:
$this->assertEquals(400, $this->_response->getStatusCode());
$expected = [
'exception' => 'BadRequestException',
'message' => AuthzError::REQUEST_AUTHORIZATION_HEADER_PAYLOAD_FAIL
'url' => '/users/authenticate',
'code' => 400,
// 'exceptions' => [new stdClass()], <----- if I don't have this line, test fails
];
$expected = json_encode($expected);
$this->assertEquals($expected, (string) $this->_response->getBody());
See how I have to have the exceptions
key in my array, with its value set to an array of a single stdClass object? That's yucky, no? It certainly feels very hacky to me. So I started tracking down where it could have come from.
It turns out that the exception getting rendered doesn't have the $this->error
property set (unknown why) and so these lines (in the MixerApiExceptionRender):
$exceptions = [$exception]; // this is the offending line
$previous = $exception->getPrevious();
while ($previous != null) {
$exceptions[] = $previous;
$previous = $previous->getPrevious();
}
are resulting in an array with a single null entry, which gets encoded to the weird JSON as shown above.
Expected Behavior
I feel like the way it should behave is to do a null check on $this->error
and set $exceptions = [];
if it is null.
Steps to Reproduce
I'm just throwing basic exceptions from my controller like this, but as I mentioned above this could be wrong:
throw new BadRequestException(
AuthzError::REQUEST_AUTHORIZATION_HEADER_REQUIRES_BASIC_SCHEME->description(true)
);
One other solution I considered was wrapping the Cake exceptions in my own custom exceptions which make sure to set $this->error
but it also seems like a null check would be beneficial here.
Version and Platform (please complete the following information):
Attachments
N/A
This class has no coverage.
Installer needs the following updates:
Allow users to catch exceptions and get the invalid entity. It's currently marked private with no getter.
Throw a BadRequestException
Output:
Warning (2) : Undefined variable $exceptions [in /srv/app/vendor/cakephp/cakephp/templates/element/exception_stack_trace.php, line 20]
Warning (2) : foreach() argument must be of type array|object, null given [in /srv/app/vendor/cakephp/cakephp/templates/element/exception_stack_trace.php, line 20]
If you want to customize this error message, create templates/Error/error400.php
Output does not contain php warnings
An EventListenerLoader
which loads all events in App\Event
by default. The load()
method can accept a string which is used to load listeners from another namespace.
When there is an entity mismatch throw custom exception instead of letting cake throw a serialization exception.
This occurs when the return value of getJsonLdContext()
cannot be mapped to an entity,
Add bin/cake mixerapi install
to documentation.
What Happened
In demo went to http://localhost:8080/public/contexts/actors and encountered exception:
Class not found for actorsTable in App\Model\Table\
Expected Behavior
JsonLdContext is rendered
Steps to Reproduce
Fix in JsonLdContextComponent::build
$table = NamespaceUtility::findClass(
Configure::read('App.namespace') . '\Model\Table\\',
Inflector::camelize(Inflector::pluralize($entityName)) . 'Table'
);
Version and Platform (please complete the following information):
Add getQuery
methods to Read service and interface. There are scenarios where a user may want to use the DI service add modify the query, associations etc...
Adding additional mimetypes for hal and jsonld can be removed from MixerApi\Core\Response\ResponseModifier
. These were added since support for CakePHP 4.1 or lower didn't have these types, but only CakePHP 4.2 or higher will be supported now.
What Happened
Unable to add Lib/assets/routes.php
to preload file.
Expected Behavior
Should be able to add Rest files to preload
Steps to Reproduce
Lib/assets/routes.php
to preload file.Version and Platform (please complete the following information):
Application should not report details when debug is off.
"type": "cakephp-plugin",
Requires CakePHP 4.2 which is still in RC
Add stack trace to responses when debug mode is enabled.
Example:
{
"exception": "RecordNotFoundException",
"message": "Record not found in table \"actors\"",
"url": "/admin/actors/123123",
"code": 500,
"trace": [
{
"file": "/var/www/api/vendor/cakephp/cakephp/src/Datasource/QueryTrait.php",
"line": 514
},
{
"file": "/var/www/api/vendor/cakephp/cakephp/src/ORM/Table.php",
"line": 1545,
"function": "firstOrFail",
"class": "Cake\\ORM\\Query",
"type": "->",
"args": []
},
{
"file": "/var/www/api/plugins/AdminApi/src/Controller/ActorsController.php",
"line": 125,
"function": "get",
"class": "Cake\\ORM\\Table",
"type": "->",
"args": [
[
"123123"
],
{
"contain": []
}
]
},
There are a few different places this could be added, MixerApi/Rest makes the most sense.
Add an event to MixerApiExceptionRenderer::render
which allows users to alter the exception message and perform additional logic.
What Happened
Web exceptions (html) output to CLI when an exception is encountered running a command.
Expected Behavior
CLI exceptions are displayed.
Steps to Reproduce
Proposed change:
public function render(): ResponseInterface
{
if (PHP_SAPI === 'cli') {
$request = $request ?? Router::getRequest();
return (new ConsoleExceptionRenderer($this->error, $request, $this->_config))->render();
}
}
Placeholder, see Actor Entity in demo, public vs admin.
Event must use variable $errorDecorator
What happened
Unable to use @throws \MixerApi\ExceptionRender\ValidationException
in docblock on add()
method to specify status code in openapi.
2021-01-04 10:54:19 Error: [InvalidArgumentException] Invalid status code: 0. Use a valid HTTP status code in range 1xx - 5xx. in /var/www/personal/mixerapi/demo/vendor/cakephp/cakephp/src/Http/Response.php on line 634
Stack Trace:
- /var/www/personal/mixerapi/demo/vendor/cakephp/cakephp/src/Http/Response.php:618
- /var/www/personal/mixerapi/mixerapi-dev/plugins/exception-render/src/MixerApiExceptionRenderer.php:66
- /var/www/personal/mixerapi/demo/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php:143
- /var/www/personal/mixerapi/demo/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php:125
- /var/www/personal/mixerapi/demo/vendor/cakephp/cakephp/src/Http/Runner.php:73
- /var/www/personal/mixerapi/demo/vendor/cakephp/debug_kit/src/Middleware/DebugKitMiddleware.php:60
- /var/www/personal/mixerapi/demo/vendor/cakephp/cakephp/src/Http/Runner.php:73
- /var/www/personal/mixerapi/demo/vendor/cakephp/cakephp/src/Http/Runner.php:58
- /var/www/personal/mixerapi/demo/vendor/cakephp/cakephp/src/Http/Server.php:90
- /var/www/personal/mixerapi/demo/webroot/index.php:40
Expected
HTTP 422 to appear in OpenAPI/Swagger/Redoc
Steps to Reproduce
@throws \MixerApi\ExceptionRender\ValidationException
to docblock in a controller add()
action.What Happened
RunTimeException was thrown and cake debug is not showing stack trace
Notice (8): Undefined variable: trace [CORE/templates/element/exception_stack_trace_nav.php, line 21]
Warning (2): Invalid argument supplied for foreach() [CORE/templates/element/exception_stack_trace_nav.php, line 21]
Expected Behavior
Shows stack trace
Steps to Reproduce
See steps in #64
Potential fix in MixerApiExceptionRenderer::debugViewVars
if (!Configure::read('debug')) {
return $viewVars;
}
Version and Platform (please complete the following information):
Site is not very SEO friendly right now. Improve title, description and h# tags.
Currently, AutoRouter will generate routes for all CRUD routes if any CRUD route exists. Change to only generate a route if the corresponding action exists (i.e. only create GET /
if index()
exists).
What Happened
\Cake\Datasource\Exception\MethodNotAllowedException
is invalid
Expected Behavior
\Cake\Http\Exception\MethodNotAllowedException
Steps to Reproduce
Version and Platform (please complete the following information):
What Happened
Tried deleting a record that doesn't exist via swagger interface. An exception is generated which causes swagger to crash.
Expected Behavior
404 response
Steps to Reproduce
Version and Platform (please complete the following information):
When model entity validation fails in a Command ValidationException is thrown. The exception should not run in PHP CLI.
Add @throws \MixerApi\ExceptionRender\ValidationException
to add() and edit() doc blocks. This should be conditional on the ExceptionRender plugin being loaded.
What Happened
\Cake\Datasource\Exception\MethodNotAllowedException
is incorrect
Expected Behavior
Use @throws \Cake\Http\Exception\MethodNotAllowedException
Version and Platform (please complete the following information):
Ref: mixerapi/mixerapi#3
This method is currently locating an Entity by string, inflection and direct instantiation of the table instance. This seems fraught with problems. Instead, the method should take a table alias string, use the TableLocator class, and then pass that into the ModelDecorator.
Pagination is not shown when using formatResults because a ResultSetDecorator instance is returned.
https://mixerapi.com/plugins/json-ld-view/
See link to "config/jsonld_config"
Waiting on PHP 8 support phpmd/phpmd#853
The method relies on ConnectionManager::get('default')
to get the connection. This will cause problems for users which use multiple connections. Use the connection from the Table instance instead.
Document Configuration class.
What Happened
A \Cake\Datasource\Exception\RecordNotFoundException
was thrown and a 500
status code was given.
Expected Behavior
A 404 status code
Steps to Reproduce
\Cake\Datasource\Exception\RecordNotFoundException
Version and Platform (please complete the following information):
Attachments
If applicable, add screenshots or swagger.json
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.