This is curious.
I created a hook to update some data of related collections after an update. The code is like this:
#Votes.after.insert (userId, doc) ->
person = People.findOne name: doc.candidate
person.votes += 1
When I insert a new Vote everything works fine: the hook is called and the votes are updated just fine. However I got this on the server log:
Exception while invoking method '/votes/insert' TypeError: Object [object Object] has no method 'findOne'
and this on the console of the browser:
errorClass {error: 500, reason: "Internal server error", details: undefined, message: "Internal server error [500]", errorType: "Meteor.Error"}
I didn't understand why I got those errors if everything worked fine.
Related
I am not sure if I am just doing something wrong or if this is actually not working. I want to display the original publication error on the client, in case I catched one:
Meteor.publish('somePub', function (args) {
const self = this
try {
// ... publication logic
catch (pubErr) {
self.error(pubErr)
}
})
On the client I am "catching" this error via the onStop callback:
Meteor.subscribe('somePub', args, {
onStop: function (e) {
// display e to user
}
})
However, while on the server the pubErr is a Meteor.Error and according to the documentation it should be sent to the client, the client just receives a generic sanitized error message:
on the server
{
stack: "useful stack of actual method calls",
error: "somePub.failed",
reason: "somePub.invalidArguments",
details: { arg: undefined }
}
on the client
{
stack: "long list of ddp-message calls",
isClientSafe: true,
error: 500,
reason: "Internal server error",
details: undefined,
message: "Internal server error [500]",
errorType: "Meteor.Error"
}
Note: I also tried to add the error to itself as sanitizedError field, as in the documentation mentioned, but no success either.
Am I missing something here?
Actually I found the answer to the issue after being pointed into the right direction.
The example code works fine on a new project, so I checked why not in my project and I found, that I did not surround the arguments validation using SimpleSchema by the try/catch (unfortunately my question was poorly designed as it missed this important fact, mainly because I abstracted away the schema validation from the publication creation):
Meteor.publish('somePub', function (args) {
pubSchema.validate(args) // throws on fail
const self = this
try {
// ... publication logic
catch (pubErr) {
self.error(pubErr)
}
})
So I thought this could not be the issue's source but here is the thing: Simple Schema is not a pure Meteor package but a NPM package and won't throw a Meteor.Error but a custom instance of Error, that actually has the same attributes (error, errorType, details) like a Meteor.Error, see this part of the source code of a validation context.
So in order to pass the correct information of a SimpleSchema validation error to the client you should
wrap it in a try/catch
add the isClientSafe flag to it
alternatively convert it to a Meteor.Error
Attach a custom Meteor.Error as sanitizedError property to it
When I am hitting this function directly by URL it worked and this insert data in Firebase object
addCountry: function (req, res) {
var ref = db.ref();
var usersRef = ref.child("country");
usersRef.push({
name: 'United States',
is_deleted: 0,
});
return res.view('city-listing');
}
But when I called this function by the form submit post method then it will throw the error:
"error: Sending 500 ("Server Error") response:
Error: Can't set headers after they are sent."
Error: Can't set headers after they are sent.
Error occurs if you are sending the view more than once in the same route handler . It had happened to me once too. Check that you don't have more than one view related rendering which might execute twice.
While testing DocumentDb stored procedures I intentionally created a document with a duplicate id so that I can observe the DocumentClientException. According to the documentation at http://azure.github.io/azure-documentdb-js-server/Collection.html#.ErrorCodes I was expecting the exception to have a 409 status code indicating Conflict.
The stored procedure code is as follows:
isAccepted = collection.createDocument(collectionLink,
duplicateIdDoc,
{ disableAutomaticIdGeneration: true },
function(err, createdDoc, options){
if (err) throw err; // Rollback
});
I do receive an exception but the error code is 400 (BadRequest). The message text indicates the correct problem. A resource with the specified id or name already exists.
"Message: {\"Errors\":[\"Encountered exception while executing function. Exception = Error: {\\"Errors\\":[\\"Resource with specified id or name already exists\\"]}\r\nStack trace: Error: {\\"Errors\\":[\\"Resource with specified id or name already exists\\"]}\n at Anonymous function (duplicateIdTest.js:56:26)\n at Anonymous function (duplicateIdTest.js:685:29)\"]}\r\nActivityId: 886230cf-8d49-433e-845f-8cc7c2ae486d, Request URI: /apps/514defcb-ac21-44e6-a8e0-c7b785523c6c/services/32782613-7101-4924-97b0-604052a6723b/partitions/be6c2ec8-130c-4596-90a2-b1807977dd0b/replicas/131240065159522367p"
Am I missing something? Thanks.
All errors thrown inside stored procedures are propagated as 400 (BadRequest). However, individual calls to the database like createDocument return the same error codes as the REST API.
For example, you can check the value of err.code === 409 inside your callback to validate that crateDocument failed due to a conflict. amd not something else.
err.code wouldn't work, Use err.number in your callback to handle known exception
Ex: err.number === 409 for conflict
I am using a JavaScript plug-in and if there is an error it expects format like;
{error: 'You are not allowed to upload such a file.'}
In my MVC Web API I am throwing error like;
var error = string.Format("An error has been occured. Please try again later.");
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, error));
and it is represented in HTTP response like below;
{"Message":"An error has been occured. Please try again later."}
how can I achieve to return in first way?
You can create an anonymous object
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError,new { error = "your error message here!"}));
I have a meteor application that starts to be quite large. I have still quite important problems to debug my application for exemple I have a error :
Uncaught TypeError: Cannot read property 'nodeType' of null domutils.js?52c3c7ff9e0acd52ac427a8f103760e222ba2722:295
Uncaught TypeError: Cannot read property '_spark_bY6hxpJRdJcb2nynQ' of null
I cannot find the source of the error.
I was having the same problem. For me it occurred when I clicked a link which caused a new template to load. When I added:
event.stopImmediatePropagation();
as shown below, the error was corrected.
Template.define_blocks.events({
'click #tb_yes': function(event) {
event.preventDefault();
event.stopImmediatePropagation();
});