Exception when doing a Graph Query in SPFX 1.6 - sharepoint

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?

Related

How to open web brower by using AWS post lambda

I have written the piece of code below:
static async postSearchResult(httpContext: HttpContext, injector: Injector) {
const log = injector.get(Log);
const service = injector.get(Service);
try {
let result = await service.redirectToUI(JSON.parse(httpContext.getRequestBody()));
httpContext.ok(result, 200, {'Content-Type': 'application/json'});
} catch (e) {
httpContext.fail(e, 500);
}
}
protected redirectToUI(response: any) {
// If any post api call happened then it should open web browser and pass some field as query parameter
window.open("https://www.google.com?abc=response.abc");
return response ? response : "failed";
}
Here I am getting the following error :
Execution failed ReferenceError: Window is not defined
What am I doing wrong?
What you are trying to accomplish doesn't make much of a sense. Lambda is a back-end service. To open new browser window, you need to use front-end JavaScript, not back-end Node (on the back-end, you have no access to the front-end window object).
If you want to open a new browser window as a reaction to some back-end response, then you can send some indicator in the HTTP response (i.e shouldOpenNewWindow: true as a part of the response object), parse that response on the front-end and it the indicator is present, then you can issue window.open command. But it has to be done on front-end.

Error Getting Geoposition from Browser using Angular Dart

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!

alert in SSJS Library

I have a function in SSJS Library. I would like get Client Side alert in Library. What i tried was not worked. I think I miss something. :(
function docAlive()
{
try
{
var otherDoc:NotesDocument= null;
if (funcDoc.getItemValueString("DocUNID")!="")
{
var otherDoc:NotesDocument = dbKontak.getDocumentByUNID(funcDoc.getItemValueString("DocUNID"))
if (otherDoc==null)
{
hataKod = "10001";
hataMsg = "There is no document :( Created One";
print (hataKod +": "+hataMsg);
view.postScript("alert('"+hataKod + " - " +hataMsg+"');");
}
}
return otherDoc;
}
catch (e)
{
e.toString();
}
}
view.postScript() will trigger a client-side alert, but as Tim Tripcony mentions, not in all events. And the alert will only be triggered after the function and any other code for the partial refresh has completed. At that point the HTML to trigger the (Client-Side) JavaScript alert will be posted back to the browser and the browser will action it.
If you want to throw an error back to the browser, I would strongly recommend XPages OpenLog Logger (and not just because I contribute and support it on OpenNTF). openLogBean.addError(e) will log the error to OpenLog and post an error message back to the browser.
The message is passed to the server using facesMessage.addMessage(), as documented here http://www.intec.co.uk/returning-error-messages-from-ssjs-through-the-facescontext/. I believe there are additional options for managing different message levels (e.g. WARNING, CONFIRMATION). FacesMessage is a standard Java (in this case, JSF) construct, so the documentation for it on the web is valid for XPages as well.

Calling an XAgent from a traditional Domino web app via AJAX

I have an XAgent I have created that works just fine via window.location but I can't get it to work via AJAX. This agent is called from a delete button on a popup div, so rather than writing to my responseStream in my XAgent, I'd prefer to just run my agent and close my popup via javascript when it is finished.
My XAgent is called by the URL doc.$DBPath.value + "/xAgent_DeleteDemand.xsp?open&id=" + doc.$DocUNID.value and looks like this:
javascript:importPackage(foo);
try {
var url:java.lang.String = context.getUrl().toString();
print(url);
if (param.containsKey("id")) {
var unid = param.get("id");
} else {
throw "No unid given";
}
XAgent.deleteDemand(unid);
} catch (e) {
print(e);
}
My actual code is in the foo package but that doesn't seem relevant because I'm not even getting my URL printed. I can say the the URL being generated and called works just fine using window.location so it is safe to assume that the problem is elsewhere.
I have a sneaking suspicion that maybe context doesn't have any meaning when called via AJAX from a non XPage app, but I don't know for sure.
I don't think there is anything special about my AJAX code but here it is just in case. It has been working fine for a long time.
function createAJAXRequest(retrievalURL, responseFunction) {
if (window.ActiveXObject) {
AJAXReq = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
AJAXReq = new XMLHttpRequest();
}
showHideIndicator("block")
var currentTime = new Date()
AJAXReq.open("GET", retrievalURL + "&z=" + currentTime.getTime());
AJAXReq.onreadystatechange = eval(responseFunction);
AJAXReq.send(null);
}
I'm not sure what the immediate problem would be, but as some troubleshooting steps:
The resultant URL is just server-relative and not on a different server+protocol combination, right?
Do you see anything on the browser's debug console when clicking the button?
Is there an entry in the browser's debug Network panel for the request at all?

How to handle Code Error 500 in Richfaces

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");

Resources