-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improving UX when a http exception is encountered #11490
Merged
Merged
Changes from 6 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
3521bd7
Revert "Add missing ""
RehanChalana 75f13fc
Created SimpleHttpResponse class to simplify HTTP Response handling
RehanChalana d05fb63
Refactored FetcherClientException to use SimpleHttpResponse, allowing…
RehanChalana fd0cd11
replaced API keys with [REDACTED] in the error messages
RehanChalana 6e91ce3
Created SimpleHttpResponse instance from HttpURLConnection and inclu…
RehanChalana c4de9f5
improved UX when a http error is encountered
RehanChalana 3c4a722
Update tools.md
RehanChalana 2de617a
check-style fixes
RehanChalana 71ff51c
Merge remote-tracking branch 'origin/issue_11223' into issue_11223
RehanChalana 0919167
check-style fixes
RehanChalana cad3f7e
moved api_key removal regex to static Pattern with Pattern.compile
RehanChalana b21a7af
extract max response length to a class constant MAX_RESPONSE_LENGTH
RehanChalana 7a30b01
moved ParserResult to Callable for achieving asynchronous execution
RehanChalana cf88105
changed the content of dialogue box to include http response and resp…
RehanChalana c02816e
updated SearchBasedParserFetcher
RehanChalana 0294c11
updated PagedSearchBasedParserFetcher to not expose api keys in the F…
RehanChalana a0a7643
Merge remote-tracking branch 'origin/main' into issue_11223
koppor 3228418
Add TODO
koppor de2dfb2
Merge remote-tracking branch 'origin/main' into issue_11223
koppor 84351ef
More intuitive ordering
koppor 95054b1
No error display, but new ParserResult from error
koppor 3abb7a2
MAke use of SimpleHttpResponse
koppor 91440e5
Fix NPE
koppor e6949bd
Add missing quotes and dots - and fix Citation Style processing l10n
koppor 1d97b76
Fix handling of errors at CiteSeer
koppor 7663f0e
"Fix" display of error messages
koppor 1ab6c2a
Add TODO
koppor 8ee95ce
feat: Added toString to SimpleHttpResponse
RehanChalana 2ba9a6e
refactor: update logger to display SimpleHttpResponse
RehanChalana 2f58945
Merge branch 'main' into issue_11223
koppor 84bc323
Make FetcherException URL-aware
koppor 7801226
Use FetcherException more often
koppor 836b997
Add some debug
koppor 89c845d
Keep response body
koppor ca3b01c
Move default implementation to "real" class
koppor 61d5334
Merge remote-tracking branch 'origin/main' into issue_11223
koppor ded5c56
Keep URL and HTTP untranslated
koppor cb350b0
Delete 2x "ofUrl"
koppor 7687bbd
Remove "ofUrl" and dummy constructors
koppor 394b429
Make FetcherException(URL url, SimpleHttpResponse httpResponse) prote…
koppor d151e2b
Adapt test
koppor 847c3bf
Fix connection opened twice
koppor 1a3da17
Adapt test
koppor 861d2b0
Merge branch 'main' into issue_11223
koppor ca979c9
Remove obsolete localization
koppor d6d16ac
Fix instanceOf Pattern
koppor 3405e21
.formatted works.
koppor d92e2a5
Add CHANGELOG.md entry
koppor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.jabref.http.dto; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public record SimpleHttpResponse(int statusCode, String responseBody , String responseMessage) { | ||
subhramit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public SimpleHttpResponse(int statusCode,String responseBody,String responseMessage) { | ||
this.statusCode=statusCode; | ||
this.responseBody=truncateResponseBody(responseBody); | ||
this.responseMessage=responseMessage; | ||
} | ||
|
||
public SimpleHttpResponse(HttpURLConnection connection) throws IOException { | ||
this( | ||
connection.getResponseCode(), | ||
getResponseBody(connection), | ||
connection.getResponseMessage() | ||
); | ||
} | ||
|
||
/** | ||
* Truncates the response body to 1 KB if it exceeds that size. | ||
* Appends "... (truncated)" to indicate truncation. | ||
* | ||
* @param responseBody the original response body | ||
* @return the truncated response body | ||
*/ | ||
private static String truncateResponseBody(String responseBody) { | ||
byte[] bytes = responseBody.getBytes(StandardCharsets.UTF_8); | ||
int maxLength = 1024; // 1 KB | ||
subhramit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (bytes.length > maxLength) { | ||
// Truncate the response body to 1 KB and append "... (truncated)" | ||
return new String(bytes, 0, maxLength, StandardCharsets.UTF_8) + "... (truncated)"; | ||
subhramit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
// Return the original response body if it's within the 1 KB limit | ||
return responseBody; | ||
} | ||
|
||
/** | ||
* Reads the response body from the HttpURLConnection and returns it as a string. | ||
* This method is used to retrieve the response body from the connection, | ||
* which may contain error messages or other information from the server. | ||
* | ||
* @param connection the HttpURLConnection to read the response body from | ||
* @return the response body as a string | ||
* @throws IOException if an I/O error occurs while reading the response body | ||
*/ | ||
private static String getResponseBody(HttpURLConnection connection) throws IOException { | ||
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getErrorStream()))) { | ||
String inputLine; | ||
StringBuilder content = new StringBuilder(); | ||
while ((inputLine = in.readLine()) != null) { | ||
content.append(inputLine); | ||
} | ||
return truncateResponseBody(content.toString()); | ||
subhramit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you sure about that? That does not seem right...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry i am not aware when i changed the file , must have been a mistake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to be sorry, mistakes happen and we learn. as a general rule, always check your changes before committing them. its easy if you use "git gui" to commit instead of the command line or the integrates tools in the ide.