How to deal with the error message of "CDbCommand failed to execute the SQL statement FOREIGN KEY" in yii1.1 - yii

I am encounted an error of "CDbCommand failed to execute the SQL statement FOREIGN KEY" when I wanted to delete a record on my admin page. I know it is saying the record has a constraint through foreign key. But how to deal with this error message? For example, just warn "you can not delete this record...".
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (yxbeauty.tbl_project_user_role, CONSTRAINT tbl_project_user_role_ibfk_1 FOREIGN KEY (project_id) REFERENCES tbl_project (id))

I tried to use the try{...} and catch{...} to resolve above program, my code is as below.
public function actionDelete($id)
{
try{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not
redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] :
array('admin'));
}
}
catch (Exception $e) {
echo 'warning: ' . $e->getMessage();
}
}
But, I could not echo the warning message. Can you give me your advise?

Related

Directus delete Item by ID

How can you delete a item via Api in Directus?
According to the doku the path would be:
DELETE /items/:collection/:id
I tried this but only got an error:
DELETE /items/parking_reservations/61
"errors": [
{
"message": "\"value\" must contain at least one of [query, keys]",
"extensions": {
"code": "FAILED_VALIDATION"
}
}
]
You can delete an item via the API in Directus using the DELETE method. You can perform this action by sending a request with the item's id to the items endpoint. For example, if you wanted to delete an item with the id of 42, you would send a DELETE request to the following endpoint: /api/1.1/tables/<table_name>/rows/42.

AWS Cognito Respond to New_Password_Required challenge returns "Cannot modify an already provided email"

An app that has been working successfully for a couple years has started throwing the following error whenever trying to respond to the NEW_PASSWORD_REQUIRED challenge with AWS Cognito:
{"__type":"NotAuthorizedException","message":"Cannot modify an already provided email"}
I'm sending the below, which all seems to match the docs.
{
"ChallengeName": "NEW_PASSWORD_REQUIRED",
"ClientId": <client_id>,
"ChallengeResponses": {
"userAttributes.email": "test#example.com",
"NEW_PASSWORD": "testP#55w0rd",
"USERNAME": "testfake"
},
"Session": <session_id>
}
Nothing has changed on the front end; is there a configuration change we might have done on the Cognito/AWS side that might cause this error?
I started getting the same error recently. I'm following Use case 23 Authenticate a user and set new password for a user. After some investigation, I found that it is the email attribute in userAttributes that's causing completeNewPasswordChallenge to throw the error. The userAttributes I get from authenticateUser used to be an empty object {}, but it now looks like this:
{ email_verified: 'true', email: 'test#example.com' }
I had to delete the email attribute (as well as the email_verified attribute as shown in the example code in Use case 23) before using the userAttribute for a completeNewPasswordChallenge. So my code is now like this:
cognitoUser.authenticateUser(authenticationDetails, {
...
newPasswordRequired: function(userAttributes, requiredAttributes) {
// the api doesn't accept this field back
delete userAttributes.email_verified;
delete userAttributes.email; // <--- add this line
// store userAttributes on global variable
sessionUserAttributes = userAttributes;
}
});
// ... handle new password flow on your app
handleNewPassword(newPassword) {
cognitoUser.completeNewPasswordChallenge(newPassword, sessionUserAttributes);
}
I guess aws changed their api recently, but I haven't found any doc about this change. Even though the value of the email attribute is the same as the actual email of the user, it throws the Cannot modify an already provided email error if you include it in the request. Deleting it solves the issue.

set default error messages for mutations in Hasura

I am using the Hasura console. If I get an error, I see a message like this:
{
"errors": [
{
"extensions": {
"path": "$.selectionSet.insert_one.args.object",
"code": "constraint-violation"
},
"message": "Uniqueness violation. duplicate key value violates unique constraint \"vehicle_number_plate_key\""
}
]
}
Is there any way that I can use the console to set a custom error message? I couldn't find any such option on the console.
Not sure if there is a way to customize the error messages that are generated by Hasura.
However, if this is to be consumed by a single frontend client, you can just let the frontend client define its own error messages.
This is also practical to support multi-language error messages if the need arises.

"error trying invoke chaincode. Error: chaincode error (status: 500, message: TypeError: cannot read property 'getFullyQualifiedIdentifier' of null)",

I am getting below error while following tutorial here.
https://hyperledger.github.io/composer/unstable/managing/current-participant.html
I have created one Participant and issued identity to it. But in my transaction processor function,when I verify the participant ID of the current participant by using the getCurrentParticipant function through rest apis I get below error.
{
"error": {
"statusCode": 500,
"name": "Error",
"message": "error trying invoke chaincode. Error: chaincode error (status: 500, message: TypeError: cannot read property 'getFullyQualifiedIdentifier' of null)",
"stack": "Error: error trying invoke chaincode. Error: chaincode error (status: 500, message: TypeError: cannot read property 'getFullyQualifiedIdentifier' of null)\n at _initializeChannel.then.then.then.then.catch (/home/praval/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:847:34)"
}
}
Can anybody explain the reason?
It looks like the mapping from certificate to participant is not in place. The easiest way to test this is to use the composer identity issue command and then use composer network ping -- which will return the current participant. Once that is working then getCurrentParticipant() should work.
https://hyperledger.github.io/composer/managing/identity-issue.html
When you composer network ping your participant will try to access the network metadata. The ACL rule below will permit this access. Please ensure that you are using the latest version of the basic-sample-network which includes this rule.
rule SystemACL {
description: "System ACL to permit all access"
participant: "org.hyperledger.composer.system.Participant"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}

Jmeter http post sampler syntax

I'm triyng to test a rest api using jmeter script. When I launch the test, I get the following exception:
{"timestamp" : 1463775753585,
"status" : 400,
"error" : "Bad Request",
"exception" : "org.springframework.http.converter.HttpMessageNotReadableException",
"message" : "Could not read JSON: (was java.lang.NullPointerException) (through reference chain: com.tutos.example.models.Product[\"category\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.tutos.example.models.Product[\"category\"])",
"path" : "/product"
}
Here is my data of post:
{"code":${productCode}, "intitule":"${productName}", "cost":"${cost}", "category":{"id":"${categoryId}"}}
But when I remove the property category, everything is OK.
What am I missing please ?