breeze entitiesWithErrors not found but instead found entityErrors - breeze

The error object that is returned from breeze manager saveChanges() don't have the array entitiesWithErrors, but instead has the entityErrors array (perhaps is as it is on breeze.js version: 1.4.12, metadataVersion: 1.0.5)
The returned error object looks like...
Error {stack: "Error: Client side validation errors encountered", entityErrors: Array[6], message: "Client side validation errors encountered see the Errors collection on this object for more detail" entityErrors: Array[6] bla. bla..
Thus the code bellow will fail and I will need to refactor it if I am not able to work with entitiesWithErrors
function getErrorMessages(error) {
function getValidationMessages(err) {
try {
return err.entitiesWithErrors.map(function (entity) {
return entity.entityAspect.getValidationErrors().map(function (valError) {
return valError.errorMessage;
}).join('; <br/>');
}).join('; <br/>');
} catch (e) {
}
return 'validation error';
}
var msg = error.message;
if (msg.match(/validation error/i)) {
return getValidationMessages(error);
}
return msg;
}

This breaking change was made in Breeze version 1.4.0. From the release notes,
The description of client side validation errors caught during a save
before posting to the server has changed.
Client side validation errors caught during a save, but before posting
to the server, cause the save to fail and be routed to the fail
promise. The fail promise returns an error object that contains a
description of the errors. This description has changed.
Previously this error object contained an entitiesWithErrors property
that contained a list of all of the entities that had failed
validation. This property has now been replaced with the entityErrors
property. The entityErrors property returns a collection of
entityError objects as described above.
This change was made in order to retain consistency between save
failures that occurred on the server and those that failed before
posting to the server on the client.
To refactor your code, you simply do,
return error.entityErrors.map(function (entityError) {
return entityError.errorMessage;
})

Related

`#RabbitListener` `#SendTo` Reply Not Working When Returning a `org.springframework.messaging.Message<?>`

I've been successfully using a method that returns my business object with an #RabbitListener annotation.
The registered Jackson2JsonMessageConverter bean named messageConverter kicks in and perfectly converts both the incoming JSON message to my expected type and the returned business object to JSON.
// This works!!
#RabbitListener(...)
#SendTo("#{responseDestination})
MyBusinessResponseObject handle(MyBusinessRequestObject request) {
...
...
...
}
But now, when I start returning a org.springframework.messageing.Message<MyBusinessResponseObject>, then I get exceptions in the logs saying: SimpleMessageConverter only supports String, byte[] and Serializable payloads, received: com.xxx.xxx.xxx.domain.MyBusinessResponseObject
// This DOESN'T work
#RabbitListener(...)
#SendTo("#{responseDestination})
Message<MyBusinessResponseObject> handle(MyBusinessRequestObject request) {
...
...
...
}
I've tried explicitly referencing my SimpleRabbitListenerContainerFactory in the #RabbitLisener annotation's containerFactory property, but I still get the same error.
I'm not sure why a SimpleMessageConverter is kickking in in this case and where it is coming from.
How do I override that message converter that is being used to convert my new return type?
Thanks!
It's a bug; please open a JIRA Issue.

sending multiple objects to back-end post method using angular 4 http services

Hi I am trying to send two objects using http post method to backend
my environment is angular4, typescirpt, asp.net MVC 5
but it is throwing 500 internal server error
the same approach if I am passing single object to the backend my backend method is getting called
here is the code with passing single object
clientSidePostCall(Results:any,Details:any):Observable<any>{
return this._http.post(Global.ENDPOINT +'BackendMethod/',Results)
.map((response: Response) => <any>response.json())
.catch((err:any) => { throw err; });
}
the above code is working fine if I send Results object to BackendMethod if it is expecting single parameter
The same code is not working if I send multiple objects to backendMethod when it is expecting two objcets.
clientSidePostCall(Results:any,Details:any):Observable<any>{
return this._http.post(Global.ENDPOINT +'BackendMethod/',Results,Details)
.map((response: Response) => <any>response.json())
.catch((err:any) => { throw err; });
}
The above code is not working and throwing 500 internal server error
here is my backend method signature
[HttpPost]
public HttpResponseMessage BackendMethod([FromBody] resultsType Results, [FromBody] detailsType Details)
please help me with this
and I am having another doubt that can we pass object in http.get in angular 4 and typescript
In your angular code make the Results, and Details be properties of a larger object... So send this object:
const myPostBody = { resultsType: Results, detailsType: Details }
return this._http.post(Global.ENDPOINT +'BackendMethod', myPostBody)
.map((response: Response) => <any>response.json())
.catch((err:any) => { throw err; });
}
Also make sure that your API class type Results actually matches the Class Results that you're sending it
I don't know how asp.net works but the third argument of HttpClient.post is not for another post body. In fact a post request cannot have two bodies. If your backend expects an array, do:
this._http.post(url, [Results, Details])
Wrapping up child entities in a parent entity is required for HTTP Post. The child entity would usually be a business entity.
On the receiving service end, you will use the entity names as properties to receive the individual items. All this assume your entity itself is serializable.

Grails filter Error occurred initializing command object

Grails 2.5.6.
I use a filter class to validate all my requests for XSS attacks. If a parameter might be harmful we simply do not forward the request to the desired interface.
This workflow works fine except for cases where there is a command object used as a interface argument. The variable is simply empty and without any params.
if (paramsValid) {
chain.doFilter(request, response)
}else {
println("ERROR");
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
response.setStatus(400);
out.print('{"success": false, "data": "Error validating request parameters"}');
out.flush();
return;
}
Then inside a conttroller interface:
def save(MappingCmd mapping) {
println(mapping);
The mappingCmd class members are always empty. The functionally works fine without the filter. How can I make this work?

Concurrency/ToDo Sample not working

I was trying out the ToDo sample and ran into an unhandled Excaption while trying out the Concurrency Handling.
The dataservice.js contains these lines in saveFailed(error) method:
if (detail && detail.ExceptionType.indexOf('OptimisticConcurrencyException') !== -1) {
// Concurrency error
reason =
"Another user, perhaps the server, may have deleted one or all of the todos.";
manager.rejectChanges(); // DEMO ONLY: discard all pending changes
}
The client never gets to this point due to an unhandled OptimisticConcurrencyException in:
[HttpPost]
public SaveResult SaveChanges(JObject saveBundle) {
return _contextProvider.SaveChanges(saveBundle);
}
I was trying to catch this and return the Exception which was kind of stupid as the Exception is not of type SaveResult. Is this a bug or am i missing an configuration somewhere?
Greets
Any server side errors should be returned to the promise.fail handler. i.e.
em.saveChanges().then(function(saveResult) {
// normal path
}).fail(function(error) {
// your concurrency exception message will be part of the error object.
});
Error on my side here... Clicking 'Continue' on the Exception Windows in VS the javascript handler is executed.

Grails: Debugging save() or validate()

I'm somewhat new to Grails. As I create or update domain object and fire save() or validate() on an object, if the method fails, the system does not seem throw an exception. I dont see any way to examine what exactly is failing.
A typical snippet:
if (domainInstance.validate()) {
flash.message = "Succesfully updated domain object"
} else {
flash.message = "Failed to update domain object"
//throw new RuntimeException("Invalid broker")
log.error "Failed to update domain object"
}
In my case the validate fails, and I am in the dark as to why.
Could anybody shed some light on it?
If placed into a try/catch, this does not throw an exception.
mydomain.validate() is used to only validate the object. You may use mydomain.hasErrors() to load the errors object and to print what went wrong with the following statement.
if(mydomain.hasErrors()){
mydomain.errors.allErrors.each{println it}
}
And generally the way I prefer to save and update any object is
if(mydomain.hasErrors() || !mydomain.save(failOnError:true){
//action to be taken if domain validation fails.
}
By setting failOnError:true, if the save() fails, validation exception would be thrown which needs to catched in controller.
You can also set failOnError = true for the entire application in the grails config file
grails.gorm.failOnError=true
http://www.grails.org/doc/1.3.x/guide/3.%20Configuration.html#3.1.3 GORM

Resources