Mercurial > gemma
comparison pkg/imports/errors.go @ 2548:6b34d0fb4498
Improve user facing error messages for stretch area generation
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 07 Mar 2019 20:03:43 +0100 |
parents | |
children | 1cb6676d1510 |
comparison
equal
deleted
inserted
replaced
2547:5afca5bc1d7a | 2548:6b34d0fb4498 |
---|---|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 | |
2 // without warranty, see README.md and license for details. | |
3 // | |
4 // SPDX-License-Identifier: AGPL-3.0-or-later | |
5 // License-Filename: LICENSES/AGPL-3.0.txt | |
6 // | |
7 // Copyright (C) 2019 by via donau | |
8 // – Österreichische Wasserstraßen-Gesellschaft mbH | |
9 // Software engineering by Intevation GmbH | |
10 // | |
11 // Author(s): | |
12 // * Tom Gottfried <tom.gottfried@intevation.de> | |
13 | |
14 package imports | |
15 | |
16 import ( | |
17 "strings" | |
18 | |
19 "github.com/jackc/pgx" | |
20 ) | |
21 | |
22 func handleError(err error) error { | |
23 switch e := err.(type) { | |
24 case pgx.PgError: | |
25 return dbError(e) | |
26 } | |
27 return err | |
28 } | |
29 | |
30 // Handle PostgreSQL error codes | |
31 const ( | |
32 noDataFound = "P0002" | |
33 ) | |
34 | |
35 type dbError pgx.PgError | |
36 | |
37 func (err dbError) Error() string { | |
38 switch err.Code { | |
39 case noDataFound: | |
40 // Most recent line from stacktrace contains name of failed function | |
41 recent := strings.SplitN(err.Where, "\n", 1)[0] | |
42 switch { | |
43 case strings.Contains(recent, "isrsrange_points"): | |
44 return "No distance mark found for at least one given ISRS Location Code" | |
45 case strings.Contains(recent, "isrsrange_axis"): | |
46 return "No contiguous axis found between given ISRS Location Codes" | |
47 } | |
48 } | |
49 return "Unexpected database error: " + err.Message | |
50 } |