1
0
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:
2026-01-04 21:43:21 +01:00
parent f68daf4ac0
commit dae6c5da18
3 changed files with 12 additions and 7 deletions

View File

@@ -39,6 +39,7 @@ async def set_information_from_source(bookmark: Bookmark, request: Request) -> B
str(bookmark.url), headers={'User-Agent': DIGIMARKS_USER_AGENT}
)
bookmark.http_status = result.status_code
logger.info('HTTP status code %s for %s', bookmark.http_status, bookmark.url)
except httpx.HTTPError as err:
# 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))
@@ -60,8 +61,8 @@ async def set_information_from_source(bookmark: Bookmark, request: Request) -> B
# with open(filename, 'wb') as out_file:
# shutil.copyfileobj(response.raw, out_file)
# Extraction was successful
logger.info('Extracting information was successful')
# Extraction was successful
logger.info('Extracting information was successful')
return bookmark

View File

@@ -219,12 +219,13 @@ document.addEventListener('alpine:init', () => {
'title': '',
'note': '',
'tags': '',
'http_status': 0,
'strip_params': false
}
},
async startAddingBookmark() {
/* Open 'add bookmark' page */
console.log('Start adding bookmark');
console.log('Open "add bookmark" modal');
this.resetEditBookmark();
// this.show_bookmark_details = true;
const editFormDialog = document.getElementById("editFormDialog");
@@ -254,20 +255,19 @@ document.addEventListener('alpine:init', () => {
console.log('Got response');
console.log(response);
console.log(data);
if (data.ok) {
if (response.ok) {
this.bookmarkToEdit.url_hash = data.url_hash;
this.bookmarkToEdit.url = data.url;
this.bookmarkToEdit.title = data.title;
this.bookmarkToEdit.note = data.note;
this.bookmarkToEdit.tags = data.tags;
this.bookmarkToEdit.http_status = data.http_status;
} else {
console.log('Error occurred');
this.bookmarkToEditError = data.detail;
}
// this.bookmarkToEditError = 'lolwut';
} 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);
this.bookmarkToEditError = error.detail;

View File

@@ -192,6 +192,10 @@
<input id="bookmark_url" type="text" name="bookmark_url" placeholder="url"
x-on:change.debounce="$store.digimarks.bookmarkURLChanged()"
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 class="form-group">
<label for="bookmark_title">Title</label>