I have a question regarding getting a users location and an error bubbling up:
I am using this to get the user's location
#override
ngOnInit() {
window.navigator.geolocation.watchPosition().listen((position) => userPosition = position);
}
This does prompt the browser to ask for permission to share the user's location, however, it also produces an error, and the position doesn't appear to get set:
html_dart2js.dart:3558 EXCEPTION: Instance of 'PositionError'
STACKTRACE:
null
ORIGINAL EXCEPTION: Instance of 'PositionError'
I was wondering if I am doing this wrong?
In case you still need help, I was facing the same problem and came to this solution by inspecting the listen function:
window.navigator.geolocation.watchPosition().listen((
Geoposition newPosition) {
//handle your position here
}, onError: (Error e){
// handle your error here
});
Hope this helps, keep up the good work!
Related
I have a node API that is working fine when tested using postman.
But when I use this API in my angular project there occurs an error and browser don't get any response there it keep waiting for a response. When I go to console I see the error message.
How I can make that error message to be sent back to the browser with full stack trace
In general, you will need to catch that error, then populate http response object with it just the same as if you were sending successful response data back to the requestor.
Synchronous processing:
try {
// do my requested stuff
res.status(200).json({something:"returned"});
} catch(ex) {
res.status(500).json(ex);
};
Promises:
Promise.resolve()
.then(() => {
// do my requested stuff
// return my results stuff to the client
res.status(200).json({something:"returned"});
})
.catch((ex) => {
// return 500 error and exception data to the client
res.status(500).json(ex);
});
Also, as standard practice you should catch all errors, and at the very least, you should return a 500 to the browser res.status(500) so you don't leave it hanging when unexpected issues arise.
And, of course you can return html rather than json, and/or more info in the response.
Good luck.
I am using the OOB example from https://pnp.github.io/pnpjs/graph/docs/ where my render function looks like this:
public render(): void {
// A simple loading message
this.domElement.innerHTML = `Loading...`;
// here we will load the current web's properties
graph.groups.get().then(groups => {
this.domElement.innerHTML = `Groups: <ul>${groups.map(g => `<li>${g.displayName}</li>`).join("")}</ul>`;
});
}
On load the webpart will throw the following exception:
adalclient.ts:154 Uncaught (in promise) Error: Could not open pop-up window for auth. Likely pop-ups are blocked by the browser.
at AdalClient._this._displayCallback (adalclient.ts:154)
at Object.displayCall (adalclient.ts:118)
at AuthenticationContext.login (adal.min.js:2)
at adalclient.ts:176
This happens both in the workbench and when the webpart is deployed.
Am I missing a step here? Someone else having the same result?
Having a mongoose model is it possible to add error handling directly to the model using .on('error) listener?
My goal is to add custom error messages to the incoming errors depending on their origin. Also I was thinking about changing error messages to make them more user friendly.
this.model.on('error', function(error) {
if (someCondition)
error = new ApolloError('Custom message', 'NOT_FOUND')
return error;
});
Basically, I want to to receive an error with a code NOT_FOUND and a custom message whenever mongoose throws an error that satisfies some condition. Any help would be appreciated.
I've came up with the following solution, which is to use toApolloError util found in apollo-server-errors
this.model.on('error', function(error) {
toApolloError(error, 'USER_INPUT_ERROR');
});
I'm working on a Node.js app that uses statuses/show/:id to fetch a Tweet object via its ID. However, I keep getting the following error.
"Sorry, that page does not exist', code: 34"
I've been looking for solutions, but they all usually lead back to the GET method being written incorrectly. I've double checked, though, and am pretty sure I'm writing it correctly.
T.get('statuses/show/:id', { id: '759043035355312128' }, function(err, data, response) {
console.log(err);
console.log(data);
});
I've also tried inputting the ID as an int, to no avail.
Did you check if the reference to the object is correct/ try absolute path instead of relative and see if it fixes it.
I'm using Richfaces 3.2.2 and need to show the user the 500 error page when there is Exception. The issue is that when I use ajax event I can't show the user the 500 error when there is an Exception. I've already defined the error page on web.xml.
Excuse My English. Any suggestion please ?
Check the RichFaces developer guide chapter 5.10.1.
5.10.1 Request Errors Handling
To execute your own code on the client in case of an error during Ajax request, it's necessary to redefine the standard "A4J.AJAX.onError" method:
A4J.AJAX.onError = function(req, status, message){
window.alert("Custom onError handler "+message);
}
The function defined this way accepts as parameters:
req - a params string of a request that calls an error
status - the number of an error returned by the server
message - a default message for the given error
Thus, it's possible to create your own handler that is called on timeouts, internal server errors, and etc.
So, to display the server-generated error response, you'd like to do the following:
A4J.AJAX.onError = function(req, status, message){
document.open();
document.write(req.responseText);
document.close();
}
To redirect to the error page, do as follows:
A4J.AJAX.onError = function(req, status, message){
window.location = 'error.jsf';
}
You'll only need to pass mandatory error details as request parameter or let the server side store it in the session as Odelya suggested.
Related question:
Handling of HTTP 4nn/5nn errors in jQuery's ajax requests
Since you are using probably JSF1.2 and not JSF2, you can use FaceletViewHandler to handle the exceptions.
public class CustomViewHandler extends FaceletViewHandler {
...
#Override
protected void handleRenderException(FacesContext context, Exception ex) throws IOException, ELException,
FacesException {
try {
..
getSessionMap().put("GLOBAL_ERROR", ex);
getHttpResponseObject().sendRedirect("/error.jsf");
} catch (IOException e) {
log.fatal("Couldn't redirect to error page", e);
}
}
}
of course, you need to handle it in the bean, just extract the exception from session:
Throwable ex = (Exception) getSessionMap().remove("GLOBAL_ERROR");