Comments (3)
Could you send me a short example so I can try it out here.
F
On 20 Mar 2014, at 15:22, Jonathan [email protected] wrote:
Not sure the best way to fix as I haven't spent any time messing with it yet, but figure you have a good idea of how to solve this. It might be as simple as turning the DEBUG constant here to "false".
If there is an error in an internal function (database query, json_encode, etc) and it is caught and handled appropriately by the user, error_get_last() still returns the error. This means that we can intend to return an appropriate response to the user, but it will have a 500 appended (in HTML) to the response.
—
Reply to this email directly or view it on GitHub.
from apix.
Here is an example controller that you can use to replicate:
<?php
namespace Controllers;
/**
* Test controller
*/
class Test
{
/**
* Test
*
* Just a quick test
*
* @return array An array representing a category
*/
public function onRead() {
try {
$response = json_decode();
} catch (Exception $e) {
$response = "caught an error";
}
return array($response);
}
}
The response looks like this:
{
"myapi": {
"test": [
null
],
"signature": {
"resource": "GET \/test",
"status": "200 OK - successful",
"client_ip": "127.0.0.1"
},
"debug": {
"timestamp": "Thu, 20 Mar 2014 15:27:37 GMT",
"request": "GET \/api\/v2\/test HTTP\/1.1",
"headers": {
"Vary": "Accept"
},
"output_format": "json",
"router_params": [
],
"memory": "1.42 MB~1.44 MB",
"timing": "0.01 seconds"
}
}
}<h1>500 Internal Server Error</h1>#2 Shutdown:- json_decode() expects at least 1 parameter, 0 given @ /home/jspalink/dev/my-api/Controllers/Test.php:31
from apix.
Okay. This has now been fixed. There are 3 case scenarios as follow:
1. The error is NOT caught.
...
$response = json_decode();
}
which results in
{
"apix": {
"error": {
"message": "json_decode() expects at least 1 parameter, 0 given",
"code": 500
},
"signature": {
"resource": "GET \/bug",
"status": "500 Internal Server Error - failed",
2. The error is caught and re-thrown
try {
$response = json_decode();
} catch (\Exception $e) {
$response = "caught an error";
throw new \Exception($response);
}
which results in
"apix": {
"error": {
"message": "caught an error",
"code": 500
},
"signature": {
"resource": "GET \/bug",
"status": "500 Internal Server Error - failed",
…
3. The error is caught but NOT re-thrown (not advised)
try {
$response = json_decode();
} catch (\Exception $e) {
$response = "caught an error";
}
which results in
"apix": {
"test": [
"caught an error"
],
"signature": {
"resource": "GET \/bug",
"status": "200 OK - successful",
...
from apix.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apix.