Mercurial > gemma
annotate pkg/pgxutils/errors.go @ 4801:b23414a3b333
import_overview: alternative save method for csv
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 28 Oct 2019 10:02:51 +0100 |
parents | fd9f171b87e4 |
children | 4d8982fa49f9 |
rev | line source |
---|---|
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
3 // |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
6 // |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2019 by via donau |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
10 // |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
12 // * Tom Gottfried <tom.gottfried@intevation.de> |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
13 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
14 |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
15 package pgxutils |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
16 |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
17 import ( |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
18 "net/http" |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
19 "strings" |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
20 |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
21 "github.com/jackc/pgx" |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
22 ) |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
23 |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
24 const ( |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
25 notNullViolation = "23502" |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
26 foreignKeyViolation = "23503" |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
27 uniqueViolation = "23505" |
4181
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
28 checkViolation = "23514" |
4749
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
29 exclusionViolation = "23P01" |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
30 violatesRowLevelSecurity = "42501" |
4723
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
31 duplicateObject = "42710" |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
32 noDataFound = "P0002" |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
33 ) |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
34 |
4175
1fb3a62d8ea7
Made 'golint' and 'staticcheck' happy with pgxutils package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4132
diff
changeset
|
35 // ReadableError wraps a given error Err and |
1fb3a62d8ea7
Made 'golint' and 'staticcheck' happy with pgxutils package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4132
diff
changeset
|
36 // permits extraction of more user-friendly |
1fb3a62d8ea7
Made 'golint' and 'staticcheck' happy with pgxutils package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4132
diff
changeset
|
37 // error messages from it in case it is an error |
1fb3a62d8ea7
Made 'golint' and 'staticcheck' happy with pgxutils package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4132
diff
changeset
|
38 // from the PostgreSQL backend. |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
39 type ReadableError struct { |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
40 Err error |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
41 } |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
42 |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
43 func (re ReadableError) Error() string { |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
44 m, _ := re.MessageAndCode() |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
45 return m |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
46 } |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
47 |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
48 // MessageAndCode returns a user-readable message |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
49 // and a matching HTTP status code. |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
50 // If its not a pgx.PgError it defaults to |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
51 // calling the parent Error method and returns its |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
52 // result together with http.StatusInternalServerError. |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
53 func (re ReadableError) MessageAndCode() (string, int) { |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
54 if e, ok := re.Err.(pgx.PgError); ok { |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
55 return messageAndCode(e) |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
56 } |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
57 return re.Err.Error(), http.StatusInternalServerError |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
58 } |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
59 |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
60 func messageAndCode(err pgx.PgError) (m string, c int) { |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
61 |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
62 c = http.StatusInternalServerError |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
63 |
4723
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
64 // Most recent line from stacktrace contains failed statement |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
65 recent := strings.SplitN(err.Where, "\n", 1)[0] |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
66 |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
67 switch err.Code { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
68 case notNullViolation: |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
69 switch err.SchemaName { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
70 case "waterway": |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
71 switch err.TableName { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
72 case "gauges": |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
73 switch err.ColumnName { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
74 case "objname": |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
75 m = "Missing objname" |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
76 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
77 case "geom": |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
78 m = "Missing lat/lon" |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
79 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
80 case "zero_point": |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
81 m = "Missing zeropoint" |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
82 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
83 } |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
84 } |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
85 } |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
86 case foreignKeyViolation: |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
87 switch err.SchemaName { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
88 case "waterway": |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
89 switch err.TableName { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
90 case "gauge_measurements", "gauge_predictions", "bottlenecks": |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
91 switch err.ConstraintName { |
4442
49aa67fb2b6d
Improve error message if predictions reference no valid gauge
Tom Gottfried <tom@intevation.de>
parents:
4441
diff
changeset
|
92 case "waterway_bottlenecks_reference_gauge", |
49aa67fb2b6d
Improve error message if predictions reference no valid gauge
Tom Gottfried <tom@intevation.de>
parents:
4441
diff
changeset
|
93 "waterway_gauge_measurements_reference_gauge", |
49aa67fb2b6d
Improve error message if predictions reference no valid gauge
Tom Gottfried <tom@intevation.de>
parents:
4441
diff
changeset
|
94 "waterway_gauge_predictions_reference_gauge": |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
95 m = "Referenced gauge with matching temporal validity not available" |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
96 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
97 } |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
98 } |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
99 } |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
100 case uniqueViolation: |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
101 switch err.SchemaName { |
4719
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
102 case "users": |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
103 switch err.TableName { |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
104 case "stretches": |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
105 switch err.ConstraintName { |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
106 case "stretches_name_staging_done_key": |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
107 m = "A stretch with that name already exists" |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
108 c = http.StatusConflict |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
109 return |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
110 } |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
111 } |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
112 case "waterway": |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
113 switch err.TableName { |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
114 case "sections": |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
115 switch err.ConstraintName { |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
116 case "sections_name_staging_done_key": |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
117 m = "A section with that name already exists" |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
118 c = http.StatusConflict |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
119 return |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
120 } |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
121 } |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
122 } |
4749
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
123 case exclusionViolation: |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
124 switch err.SchemaName { |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
125 case "waterway": |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
126 switch err.TableName { |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
127 case "sections": |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
128 switch err.ConstraintName { |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
129 case "sections_name_country_excl": |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
130 m = "A section with that name already exists for another country" |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
131 c = http.StatusConflict |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
132 return |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
133 } |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
134 } |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
135 } |
4181
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
136 case checkViolation: |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
137 switch err.SchemaName { |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
138 case "waterway": |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
139 switch err.TableName { |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
140 case "sounding_results": |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
141 switch err.ConstraintName { |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
142 case "b_sounding_results_in_bn_area": |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
143 m = "Dataset does not intersect with given bottleneck" |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
144 c = http.StatusConflict |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
145 return |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
146 } |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
147 } |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
148 } |
4723
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
149 case duplicateObject: |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
150 switch { |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
151 case strings.Contains(recent, "CREATE ROLE"): |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
152 m = "A user with that name already exists" |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
153 c = http.StatusConflict |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
154 return |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
155 } |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
156 case noDataFound: |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
157 switch { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
158 case strings.Contains(recent, "isrsrange_points"): |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
159 m = "No distance mark found for at least one given ISRS Location Code" |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
160 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
161 case strings.Contains(recent, "isrsrange_axis"): |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
162 m = "No contiguous axis found between given ISRS Location Codes" |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
163 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
164 case strings.Contains(recent, "isrsrange_area"): |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
165 m = "No area around axis between given ISRS Location Codes" |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
166 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
167 } |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
168 case violatesRowLevelSecurity: |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
169 m = "Could not save: Data outside the area of responsibility." |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
170 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
171 } |
4071
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
172 m = "Unexpected database error: " + err.Message |
5867dcf8e93c
Introduced a new ReadableError type for better readable error messages of pgx.PgErrors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4063
diff
changeset
|
173 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
174 } |