Skip to content

Commit

Permalink
show errors
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
  • Loading branch information
Julien Veyssier committed Oct 20, 2021
1 parent 93d7fa5 commit 45662f3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/Service/ImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@

class ImageService {

/**
* @var string|null
*/
private $userId;
/**
* @var ShareManager
*/
Expand Down Expand Up @@ -89,7 +85,7 @@ public function downloadImageLink(string $link, string $userId): array {
}
$savedFile->touch();
if (isset($res['Content-Type'])) {
if ($res['Content-Type'] === 'image/jpg') {
if (in_array($res['Content-Type'], ['image/jpg', 'image/jpeg'])) {
$fileName = $fileName . '.jpg';
} elseif ($res['Content-Type'] === 'image/png') {
$fileName = $fileName . '.png';
Expand Down Expand Up @@ -179,12 +175,13 @@ private function simpleDownload(string $url, $resource, array $params = [], stri
//$response = $e->getResponse();
//if ($response->getStatusCode() === 401) {
$this->logger->warning('Impossible to download image: '.$e->getMessage(), ['app' => Application::APP_NAME]);
return ['error' => $e->getMessage()];
return ['error' => 'Impossible to download image'];
} catch (ConnectException $e) {
$this->logger->error('Connection error: ' . $e->getMessage(), ['app' => Application::APP_NAME]);
return ['error' => 'Connection error: ' . $e->getMessage()];
return ['error' => 'Connection error'];
} catch (Throwable | Exception $e) {
return ['error' => 'Unknown error: ' . $e->getMessage()];
$this->logger->error('Unknown error: ' . $e->getMessage(), ['app' => Application::APP_NAME]);
return ['error' => 'Unknown error'];
}
}
}
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@nextcloud/auth": "^1.3.0",
"@nextcloud/axios": "^1.7.0",
"@nextcloud/browser-storage": "^0.1.1",
"@nextcloud/dialogs": "^3.1.2",
"@nextcloud/event-bus": "^2.1.0",
"@nextcloud/initial-state": "^1.2.0",
"@nextcloud/l10n": "^1.4.1",
Expand Down
3 changes: 3 additions & 0 deletions src/components/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ import ClickOutside from 'vue-click-outside'
import { getCurrentUser } from '@nextcloud/auth'
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
export default {
name: 'MenuBar',
Expand Down Expand Up @@ -356,6 +357,7 @@ export default {
this.insertImage(targetFilePath, this.imageCommand)
}).catch((error) => {
console.error(error)
showError(error?.response?.data?.error)
}).then(() => {
this.imageCommand = null
this.uploadingImage = false
Expand All @@ -375,6 +377,7 @@ export default {
this.insertImage(response.data?.path, command)
}).catch((error) => {
console.error(error)
showError(error?.response?.data?.error)
}).then(() => {
this.uploadingImage = false
})
Expand Down

0 comments on commit 45662f3

Please sign in to comment.