Getting the main url on which error occured in Yii 1 - yii

We have implemented an error handler for Yii 1. Also we have implemented the mail functionality with this as any error occurred an email will be send to us but the problem is we are not getting the current URL on which error is generating. Like one page controller/action can contain many images favicons etc. So if any image is missing then we are getting the image URL which showing 404 from:
$url = Yii::app()->createAbsoluteUrl(Yii::app()->request->url);
But we are not getting current URL not even in $error = Yii::app()->errorHandler->error.
So we are not getting the page in which image is absent. Please let me know if is there any way to get current page URL as I have tried many ways but all they are returning the missing images URL instead of main page URL for which images are missing.

createAbsoluteUrl() expects route as first argument - it may return random results if you provide URL instead of route (like in your code snippet).
If you want absolute URL of current request, you may use combination of getUrl() and getHostInfo():
$url = Yii::app()->request->getHostInfo() . Yii::app()->request->getUrl();

In case of error you can get current page url using Yii::app()->request->requestUri in Yii 1.

Related

Difference between UseStatusCodePagesWithRedirects and UseStatusCodePagesWithReExecute - Status Code Pages in Asp.net core

I am using UseStatusCodePages Middleware to show status code pages on my application but it shows plain text on UI without any other information,
I want to show UI with Status Code Information along with some other helpful information like Customer Support Number with more user-friendly page.
I found out we can use two extension methods to do that which is UseStatusCodePagesWithRedirects and UseStatusCodePagesWithReExecute. Only Difference I found out from Microsoft Docs is,
UseStatusCodePagesWithRedirects : Send 302 to Client.
UseStatusCodePagesWithReExecute : Send Original Status Code and Executes handler for redirect URL.
Is that the only difference?
I think that the main difference is that UseStatusCodePagesWithRedirects is redirecting you to error controller action method while UseStatusCodePagesWithReExecute is just rendering page with out redirecting
Example
Controller actions
[Route("error/404")]
public IActionResult Error404(int code)
{
return View("Error404");
}
[Route("error/{code}")]
public IActionResult Error(int code)
{
return StatusCode(code);
}
Startup Cinfigue
app.UseStatusCodePagesWithRedirects("/error/{0}");
or
app.UseStatusCodePagesWithReExecute("/error/{0}");
Case 1 (404 Error)
Url : https://localhost:5001/notexits_page
1) UseStatusCodePagesWithRedirects
Result:
Url is: https://localhost:5001/error/404
We see Error404 page
2) UseStatusCodePagesWithReExecute
Result:
Url is: https://localhost:5001/notexits_page
We see Error404 page
Case2 (401 Error)
Url : https://localhost:5001/admin/users
1) UseStatusCodePagesWithRedirects
Result:
Url is: https://localhost:5001/error/401
We stack in infinity loop
1) UseStatusCodePagesWithRedirects
Result:
Url is: https://localhost:5001/admin/users
We see default browser error page for 401 error
When Using app.UseStatusCodePagesWithRedirects("/Error/{0}") and invalid request(lets say "/abc/xyz") is raised then;
Status Code 404 is issued, app.UseStatusCodePagesWithRedirects("/Error/{0}") intercepts the request and 302 status code is issued(which means URI of the requested resource has been changed temporarily)
As 302 is issued another get request is issued which results in change of the url from
"/abc/xyz" to "/Error/404".
As the request is redirected to the specific error controller the status code for the request is 200 ok in the browser developer tool.
But When Using app.UseStatusCodePagesWithReExecute("/Error/{0}") and invalid request(lets say "/abc/xyz") is raised then;
app.UseStatusCodePagesWithReExecute("/Error/{0}") middleware intercepts the 404 status code and re-executes the pipeline pointing it to the URL
As the middleware is re executing the pipeline the original URL "/abc/xyz" in the address bar is preserved. It does not change from "/abc/xyz" to "/Error/{0}".
Also the original status Code(404 in this case) is preserved in the developer tool.

Crawler4J seed url gets encoded and error page is crawler instead of actual page

I am using crawler 4J to crawl user profile on gitHub for instance I want to crawl url: https://github.com/search?q=java+location:India&p=1
for now I am adding this hard coded url in my crawler controller like:
String url = "https://github.com/search?q=java+location:India&p=1"; controller.addSeed(url);
When crawler 4J starts the URL Crawled is :
https://github.com/search?q=java%2Blocation%3AIndia&p=1
which gives me error page.
What should I do, I have tried giving encoded url but that doesn't work either.
I had to eventually make the slightest of changes to crawler4J source code:
File Name: URLCanonicalizer.java
Method : percentEncodeRfc3986
Just commented the first line in this method and I was able to crawl and fetch my results
//string = string.replace("+", "%2B");
In my url there was + character and that was being replaced by %2B and I was getting a error page,I wonder why they have specifically replaced + character before encoding the entire URL.

API: Custom 404 not found error response structure

Considering this url: http://example.com/users/1/post/2/likes.
How can I correctly define structure of my 404 response, showing which item is not found? user, post or likes?
You can send an HTTP status code using the header() function, by starting the header with the status code number, followed by the message to send to the user.
header("404 " + $message);
The code that processes the parameters can determine which item isn't found, and put that into $message.

Extract report results with CloudConnect

I would like to extract raw report results within the CloudConnect process.
So far I have managed to get response from the raw report API end point - https://secure.gooddata.com/gdc/app/projects/{project_id}/execute/raw/
This response contains URI to the file and if I put that URI to browser, file is uploaded.
I have tried passing this URI to the following readers without success:
CSV Reader produces the following error:
------------------- Error details ------------------
Component [CSV Reader:CSV_READER] finished with status ERROR.
Parsing error: Unexpected end of file in record 1, field 1 ("date"),
metadata "outOfStock";
value: Raw record data is not available, please turn on verbose mode.
File Download - I don't know how to pass the URI through the port to "URL to Downlaod" parameter.
HTTP Connector again I don't see how to pass URI from the port.
What is the way to do this?
EDIT
If I use the HTTP Connector as suggested by #Filip, I get the following error:
Error details:
Component [HTTP connector:HTTP_CONNECTOR] finished with status ERROR. hostname in
certificate didn't match: xxx.com != secure.gooddata.com OR secure.gooddata.com
I have tried setting header to X-GDC-CHECK-DOMAIN: false with no effect.
The HTTP connector is the right component to go with. Leave the URL property empty and use the component’s property called “Input mapping”, where in the graphic editor you can assign the input edge field to the URL field.
Solution from GoodData support:
HTTP connector can be also used, but it is very complex, because
logging in to GoodData has to be created. REST connector has it built
in.
If you want to run the example graph, you have to be logged in in
CloudConnect with a user who has access to the project from where you
would like to export the report. You also have to change URL to
the one of white-labeled account in both REST connector components and change project
and report definition in the first REST connector.
So the graph that works looks like this:
Here are the main fields that you will need to set for each element:
Get Results URI - set params for POST request:
Request URL = https://secure.gooddata.com/gdc/app/projects/${GDC_PROJECT_ID}/execute/raw/
Request Body =
{
"report_req": {
"reportDefinition": "gdc/md/${GDC_PROJECT_ID}/obj/${OBJECT_ID}"
}
}
Get URI from Response - just map uri value to corresponding field:
<Mapping cloverField="uri" xpath="uri"/>
Load Results - make sure it is connected to metadata with two fields, one for response with data, other to pass through the uri.
Load Results - you will need to exclude uri field to process the data:
Exclude Fields = uri

Use URL as an API method for Slackbot in Express js

I am still new to javascript and trying to write a Slackbot in express js. I want to use the method defined in https://api.slack.com/methods/channels.history. How should this look syntacticly and how do I use it since the method is simply a URL?
You need to make an http request for the URL and you'll be returned a response with an object containing the status (ok:true|false), if there are more messages (has_more:true|false), and then an array of the actual messages (messages:array).
The response should look something like this:
{
has_more:true
messages:Array[100]
ok:true
}
The url that you make the get request to should look something like:
https://slack.com/api/channels.history?token=BOT_TOKEN&channel=CHANNEL_ID&pretty=1
Where BOT_TOKEN is the token attached to the bot you created, and CHANNEL_ID is the ID (not the name) of the channel whos history you want to get (9 uppercase alphanumeric characters, starts with a "C").
There are also a few other parameters you can include in the url. For example, "latest=", "oldest=", "inclusive=", "count=", and "unreads=". Details about those parameters can be found on the page you linked to (https://api.slack.com/methods/channels.history).
If you want to test it out in your browser's console, find a page where jQuery is loaded, open your dev tools and head into the console, and enter the following (with your bot token and channel id swapped in):
$.get('https://slack.com/api/channels.history?token=BOT_TOKEN&channel=CHANNEL_ID&pretty=1', function(response){console.log(response)});