mirror of
https://codeberg.org/diginaut/digimarks.git
synced 2026-02-04 07:00:26 +01:00
Correctly update bookmark form, and show HTTP status on error
This commit is contained in:
@@ -39,6 +39,7 @@ async def set_information_from_source(bookmark: Bookmark, request: Request) -> B
|
|||||||
str(bookmark.url), headers={'User-Agent': DIGIMARKS_USER_AGENT}
|
str(bookmark.url), headers={'User-Agent': DIGIMARKS_USER_AGENT}
|
||||||
)
|
)
|
||||||
bookmark.http_status = result.status_code
|
bookmark.http_status = result.status_code
|
||||||
|
logger.info('HTTP status code %s for %s', bookmark.http_status, bookmark.url)
|
||||||
except httpx.HTTPError as err:
|
except httpx.HTTPError as err:
|
||||||
# For example, "MissingSchema: Invalid URL 'abc': No schema supplied. Perhaps you meant http://abc?"
|
# For example, "MissingSchema: Invalid URL 'abc': No schema supplied. Perhaps you meant http://abc?"
|
||||||
logger.error('Exception when trying to retrieve title for %s. Error: %s', bookmark.url, str(err))
|
logger.error('Exception when trying to retrieve title for %s. Error: %s', bookmark.url, str(err))
|
||||||
@@ -60,8 +61,8 @@ async def set_information_from_source(bookmark: Bookmark, request: Request) -> B
|
|||||||
# with open(filename, 'wb') as out_file:
|
# with open(filename, 'wb') as out_file:
|
||||||
# shutil.copyfileobj(response.raw, out_file)
|
# shutil.copyfileobj(response.raw, out_file)
|
||||||
|
|
||||||
# Extraction was successful
|
# Extraction was successful
|
||||||
logger.info('Extracting information was successful')
|
logger.info('Extracting information was successful')
|
||||||
return bookmark
|
return bookmark
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -219,12 +219,13 @@ document.addEventListener('alpine:init', () => {
|
|||||||
'title': '',
|
'title': '',
|
||||||
'note': '',
|
'note': '',
|
||||||
'tags': '',
|
'tags': '',
|
||||||
|
'http_status': 0,
|
||||||
'strip_params': false
|
'strip_params': false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async startAddingBookmark() {
|
async startAddingBookmark() {
|
||||||
/* Open 'add bookmark' page */
|
/* Open 'add bookmark' page */
|
||||||
console.log('Start adding bookmark');
|
console.log('Open "add bookmark" modal');
|
||||||
this.resetEditBookmark();
|
this.resetEditBookmark();
|
||||||
// this.show_bookmark_details = true;
|
// this.show_bookmark_details = true;
|
||||||
const editFormDialog = document.getElementById("editFormDialog");
|
const editFormDialog = document.getElementById("editFormDialog");
|
||||||
@@ -254,20 +255,19 @@ document.addEventListener('alpine:init', () => {
|
|||||||
console.log('Got response');
|
console.log('Got response');
|
||||||
console.log(response);
|
console.log(response);
|
||||||
console.log(data);
|
console.log(data);
|
||||||
if (data.ok) {
|
if (response.ok) {
|
||||||
this.bookmarkToEdit.url_hash = data.url_hash;
|
this.bookmarkToEdit.url_hash = data.url_hash;
|
||||||
this.bookmarkToEdit.url = data.url;
|
this.bookmarkToEdit.url = data.url;
|
||||||
this.bookmarkToEdit.title = data.title;
|
this.bookmarkToEdit.title = data.title;
|
||||||
this.bookmarkToEdit.note = data.note;
|
this.bookmarkToEdit.note = data.note;
|
||||||
this.bookmarkToEdit.tags = data.tags;
|
this.bookmarkToEdit.tags = data.tags;
|
||||||
|
this.bookmarkToEdit.http_status = data.http_status;
|
||||||
} else {
|
} else {
|
||||||
console.log('Error occurred');
|
console.log('Error occurred');
|
||||||
this.bookmarkToEditError = data.detail;
|
this.bookmarkToEditError = data.detail;
|
||||||
}
|
}
|
||||||
// this.bookmarkToEditError = 'lolwut';
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// enter your logic for when there is an error (ex. error toast)
|
// enter logic for when there is an error (ex. error toast)
|
||||||
|
|
||||||
console.log('error occurred');
|
console.log('error occurred');
|
||||||
console.log(error);
|
console.log(error);
|
||||||
this.bookmarkToEditError = error.detail;
|
this.bookmarkToEditError = error.detail;
|
||||||
|
|||||||
@@ -192,6 +192,10 @@
|
|||||||
<input id="bookmark_url" type="text" name="bookmark_url" placeholder="url"
|
<input id="bookmark_url" type="text" name="bookmark_url" placeholder="url"
|
||||||
x-on:change.debounce="$store.digimarks.bookmarkURLChanged()"
|
x-on:change.debounce="$store.digimarks.bookmarkURLChanged()"
|
||||||
x-model="$store.digimarks.bookmarkToEdit.url">
|
x-model="$store.digimarks.bookmarkToEdit.url">
|
||||||
|
<p x-show="$store.digimarks.bookmarkToEdit.http_status > 202"
|
||||||
|
x-text="'HTTP statuscode: ' + $store.digimarks.bookmarkToEdit.http_status" x-cloak
|
||||||
|
class="error"></p>
|
||||||
|
<p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset class="form-group">
|
<fieldset class="form-group">
|
||||||
<label for="bookmark_title">Title</label>
|
<label for="bookmark_title">Title</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user