Skip to content

Commit

Permalink
fix(imports-service): Ogre error 500 handling (#890)
Browse files Browse the repository at this point in the history
* fix(import-service): OGRE error 500 handling

* fix lint

* remove reference to shapefile

Co-authored-by: Pierre-Etienne Lord <pe_lord@pm.me>
  • Loading branch information
josee666 and pelord authored Aug 12, 2021
1 parent 257def8 commit 696efa0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/geo/src/lib/import-export/shared/import.errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ export class ImportSRSError extends ImportError {
Object.setPrototypeOf(this, ImportNothingToImportError.prototype);
}
}

export class ImportOgreServerError extends ImportError {
constructor() {
super('Error 500 with OGRE');
Object.setPrototypeOf(this, ImportOgreServerError.prototype);
}
}
8 changes: 6 additions & 2 deletions packages/geo/src/lib/import-export/shared/import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
ImportInvalidFileError,
ImportUnreadableFileError,
ImportSizeError,
ImportSRSError
ImportSRSError,
ImportOgreServerError
} from './import.errors';
import { computeLayerTitleFromFile, getFileExtension } from './import.utils';

Expand Down Expand Up @@ -154,7 +155,8 @@ export class ImportService {
formData.append('formatOutput', 'GEOJSON');
formData.append('skipFailures', '');

this.http.post(url, formData, { headers: new HttpHeaders() }).subscribe(
this.http.post(url, formData, { headers: new HttpHeaders() })
.subscribe(
(response: { errors?: string[] } | object | null) => {
if (response === null) {
observer.error(new ImportUnreadableFileError());
Expand Down Expand Up @@ -182,6 +184,8 @@ export class ImportService {
} else if (errMsg && errMsg.startWith('ERROR 1: Failed to process SRS definition')
) {
observer.error(new ImportSRSError());
} else if (error.status === 500) {
observer.error(new ImportOgreServerError());
} else {
observer.error(new ImportUnreadableFileError());
}
Expand Down
14 changes: 13 additions & 1 deletion packages/geo/src/lib/import-export/shared/import.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ export function handleFileImportError(
'Invalid file': handleInvalidFileImportError,
'File is too large': handleSizeFileImportError,
'Failed to read file': handleUnreadbleFileImportError,
'Invalid SRS definition': handleSRSImportError
'Invalid SRS definition': handleSRSImportError,
'Error 500 with OGRE': handleOgreServerImportError
};
errMapping[error.message](
file,
Expand Down Expand Up @@ -311,6 +312,17 @@ export function handleSRSImportError(
messageService.error(message, title);
}

export function handleOgreServerImportError(
file: File,
error: Error,
messageService: MessageService,
languageService: LanguageService
) {
const title = languageService.translate.instant('igo.geo.dropGeoFile.ogreServer.title');
const message = languageService.translate.instant('igo.geo.dropGeoFile.ogreServer.text');
messageService.error(message, title);
}

export function getFileExtension(file: File): string {
return file.name
.split('.')
Expand Down
4 changes: 4 additions & 0 deletions packages/geo/src/locale/en.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"invalidSRS": {
"text": "The projection is valid. It must start with EPSG:",
"title": "Invalid projection"
},
"ogreServer": {
"title": "Ogre server error 500",
"text": "Error in convert to geojson. Maybe file is too big, try to import that file in geojson format"
}
},
"export": {
Expand Down
4 changes: 4 additions & 0 deletions packages/geo/src/locale/fr.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"invalidSRS": {
"text": "La projection est valide. Elle doit commencer par EPSG:",
"title": "Projection invalid"
},
"ogreServer": {
"title": "Erreur 500 du service Ogre",
"text": "Erreur de la conversion du fichier en geojson. Il est possible que le fichier soit trop volumineux, essayer de l'importer en format geojson"
}
},
"export": {
Expand Down

0 comments on commit 696efa0

Please sign in to comment.