jqgrid error Status: 'error'. Error code: 500 on add more meaningful message - jqgrid

I have a jqgrid which works fine. However there is a constraint in my database and I need to provide more meaningful validation method when adding.
The problem is when I submit the dialog shows the error: error Status: 'error'. Error code: 500
I would much prefer it to show the actual error caused by the exception thrown on save:
Violation of UNIQUE KEY constraint 'UKC_InvoiceId_ActivityId'. Cannot insert duplicate key in object 'dbo.InvoiceLine'. The duplicate key value is (11, 1). The statement has been terminated.
Can anybody tell me how to achieve this?

If you use ASP.NET then you can use try {...} catch (SqlException ex) {...} block over the code which implement the row insertion. You can analyse ex.Procedure, ex.Server, ex.LineNumber, ex.Message values inside of the SqlException and generate (throw) another exception with more readable message. You can use in the error message the texts typed by the user and explain which data the user have to modify to solve the problem.

Related

Change error system message in oracle apex

I have a form page and all field is required when press save the below message appear
How i can change this message to custom message "please fill all required fields " , and how i can clear error when enter value (when value change to not null).
I can't see images at the moment.
However, one option might be to create your own validation which returns error text. Something like
if :P1_NAME is null then
return ('Name must be entered');
end if;
Messages are automatically cleared once you submit the page and there are no errors left.
I am not sure if you can change system messages but you can add custom error messages with javascript if a change happens in any item.
Add a change event to the item that runs javascript and use the following code:
var item = apex.item('P1_ITEM').getValue();
if(item == null) {
//First clear the errors
apex.message.clearErrors();
// Now show new errors
apex.message.showErrors([
{
type: "error",
location: [ "page", "inline" ],
pageItem: "P1_ITEM",
message: "Name is required!",
unsafe: false
},
{
type: "error",
location: "page",
message: "Page error has occurred!",
unsafe: false
}
]);
}
However, this will not stop the user from submitting, it only allows you to better display the messages, so you must add the corresponding validations after submit.
If you want to remove the system error message from the required items, you can disable the option of Value Required on item and add a custom validation as they told you in the other response.
If you want to explore all the apex.message options better, I recommend this documentation:
https://docs.oracle.com/database/apex-5.1/AEAPI/apex-message-namespace.htm#AEAPI-GUID-D15040D1-6B1A-4267-8DF7-B645ED1FDA46
More documentation for apex.item:
https://docs.oracle.com/cd/E71588_01/AEAPI/apex-item.htm#AEAPI29448
There are some ways for how to do such things.
Firstly you have the custom Validations you can make, these are awesome and you should really try to use them if possible.
Then there is also the Error message on the saving procedure, but this just throws a custom message on procedure fail so I never use it.
What you appear to be seeing there is that you got an error message and didnt change the fields associated with the error.
If the save procedure is custom, you can also put in an EXCEPTION block before the END, and catch errors there and throw out a custom error with a custom error message.
Another thing I really like is to actually rename some common errors so I dont have to catch them all individually. Say clients may often times try to save identical data, thus breaking the PK. Oracle will throw an error, but the message is good for the developer, but less understandable for the client whom I always assume is a 3 year old kid who can barely read and will cry over everything. So I make an error handling function, add it to apex, and so when the error occurs, it throws a nice message informing the client that they have tried to add some data that already exists.
So, an error handling function associated with APEX, to rename some normal errors.
Good luck

Catching exceptions when using <int-xml:validating-filter>

I am pulling data from queue and then validating the input payload using int-xml:validating-filter. I have set throw-exception-on-rejection="true" so that exception is thrown.
I need to get hold of the exception message(validation errors) as well as the input payload. Could you please suggest the options available to capture this data?
<int-jms:message-driven-channel-adapter id="jmsIn"
destination="requestQueue" channel="orderChannel"/>
<int-xml:validating-filter id="validatingFilter"
input-channel="orderChannel"
output-channel="validOutputChannel"
discard-channel="errOutputChannel"
schema-type="xml-schema"
throw-exception-on-rejection="true"
schema-location="OrderProcessing/order.xsd"/>
You concern isn't clear, if you can catch that exception.
The code in the XmlValidatingMessageSelector looks like:
if (this.throwExceptionOnRejection) {
throw new MessageRejectedException(message, "Message was rejected due to XML Validation errors",
new AggregatedXmlMessageValidationException(
Arrays.<Throwable>asList(validationExceptions)));
}
So, that MessageRejectedException has the desired message as a cause for validation failure. And all the validation errors are represent in the AggregatedXmlMessageValidationException cause of that MessageRejectedException.

Application.Current.Properties - System.AggregateException

I'm trying to get some data from Application.Current.Properties storage. Unfortunately, any time I want to use this Dictionary, I see this error:
An exception of type 'System.AggregateException' occurred in mscorlib.ni.dll but was not handled in user code
Additional information: One or more errors occurred.
And in details I found this:
{"Error in line 1 position 206. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:Value' contains data of the 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfstring' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'ArrayOfstring' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer."}
It seems like I tried to save some non-string data to Application.Current.Properties. Unfortunately I can't run .Clear() method to erease all data, bacause I receive this error any time I'm trying to access this property.
What should I do to make it work?
Well, as its name suggests AggregateException, is just a container for one or more exceptions which may be thrown when using PLINQ or TPL.
As such exceptions may be thrown on different threads and may also occur concurrently, the system automatically catches and rethrows them within an AggregateException wrapper to ensure that they all get reported in one place. The exceptions themselves are exposed via the InnerExceptions property.
You can catch an AggregateException and check which exceptions it actually contains with code such as the following:
try
{
// perform some parallel operation
}
catch (AggregateException aex)
{
string messages = "";
foreach(Exception ex in aex.InnerExceptions)
{
messages += ex.Message + "\r\n";
}
MessageBox.Show(messages);
}
So I suggest you do this to see what is causing the problem
Please, remove your app from your device, Settings - Applications- Uninstall, this works for me. The Auth Object was crash in debug mode.Clean and Rebuild can be Helpfull to.

Best way to return "expected" Oracle exceptions to Java Groovy/Grails

Background:
In my Oracle database, I have plenty of database calls which can cause exceptions. I currently have exception handlers for all these, which call an error package. To cut a long story short, a raise_application_error is eventually raised, for expected errors, or a raise for unexpected errors, and this is sent back to the calling Java Groovy/Grails application layer.
So, for example, if a user enters an id and clicks search, I run a select query from the database. If the id doesn't exist, I have a NO_DATA_FOUND exception which performs a raise_application_error with a custom error message (i.e. "ID entered cannot be found.")
However, the application development team say they're struggling with this. They are trying to perform unit testing in Groovy and ideally want a variable returned. The SQL exceptions I am currently returning cause all tests to fail as it is an exception. Their code looks like this:
void nameOfProcedure() {
String result = storedProcedure.callDBProcedure(ConnectionType.MSSQL, val1, val2)
log.info "SQL Procedure query result value: "+ result
assertEquals("1", result)
}
They can add something like this above the test:
#Test (expected = SQLException.class)
But this means all returning SQLExceptions will pass, regardless of whether they are the right exceptions for the issue at hand.
Question:
What is the best solution to this issue? I'm being pressed to return variables from my exception blocks, rather than raise_application_errors - but I'm very reluctant to do this, as I've always been told this is simply terrible practice. Alternatively, they could make changes on their end, but are obviously reluctant to.
What's the next step? Should I be coding to return "expected" errors as variables, as opposed to exceptions? For example, if someone enters an ID that isn't found:
BEGIN
SELECT id
FROM table
WHERE id = entered_id
EXCEPTION
WHEN NO DATA FOUND THEN
RETURN 'ID cannot be found';
END
Or alternatively, should they be following a guide like this which advises using Hamcrest matchers to create their own custom exception property, which they can check against in their JUnit testing. What is best practice here?
You're right, it's terrible practice. It just 'wagging the dog'; they're being lazy to work good and wish you to spoil application design in order to please them.
Generally, unit test with exception returned should looks something like this:
try {
String result = callDBProcedure();
fail("Result instead of exception");}
catch (OracleSQLException e) {
assertEquals(e.errorCode, RAISE_APPLICATION_ERROR_CODE);}
catch (Throwable t) {
fail("Unexpected error");
}
They can upgrade this as they wish. For example, they can develop procedure 'call the SP and convert exception to anything they wish' and use it in their tests. But they should not affect application design outside testing. Never.

Custom oracle exceptions through JDBC

In a stored procedure I have used to;
raise_application_error (-20010, 'My Message');
to raise a custom error in a certain situation. What I am trying to do is when I make my JDBC call from java, to be able to identify this error as not just being a SQLException so that I can handle it differently. I though I could identify it by the errorCode, but that seems to always be 17062 and not -20010.
Is there another way to do this, or am I missing something?
you should get 20010 as your errorCode. the ORA-17062 is an error for invalid ref cursors. Are you sure the procedure you are calling throws the custom error ?

Resources