Mercurial > gemma
annotate pkg/pgxutils/errors.go @ 5307:4ba3fda13c50 zpg-exception
Fixed typo in migration script.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 28 May 2021 11:17:12 +0200 |
parents | 73563c4bba5b |
children | 2dd155cc95ec |
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 ( |
4871 | 25 // camel cased condition name = error code |
26 // from appendix A of PostgreSQL documentation | |
27 notNullViolation = "23502" | |
28 foreignKeyViolation = "23503" | |
29 uniqueViolation = "23505" | |
30 checkViolation = "23514" | |
31 exclusionViolation = "23P01" | |
32 insufficientPrivilege = "42501" | |
33 duplicateObject = "42710" | |
34 noDataFound = "P0002" | |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
35 ) |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
36 |
4175
1fb3a62d8ea7
Made 'golint' and 'staticcheck' happy with pgxutils package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4132
diff
changeset
|
37 // 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
|
38 // 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
|
39 // 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
|
40 // 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
|
41 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
|
42 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
|
43 } |
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 |
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 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
|
46 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
|
47 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
|
48 } |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
49 |
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
|
50 // 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
|
51 // 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
|
52 // 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
|
53 // 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
|
54 // 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
|
55 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
|
56 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
|
57 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
|
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 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
|
60 } |
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 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
|
63 |
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
|
64 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
|
65 |
4723
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
66 // 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
|
67 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
|
68 |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
69 switch err.Code { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
70 case notNullViolation: |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
71 switch err.SchemaName { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
72 case "waterway": |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
73 switch err.TableName { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
74 case "gauges": |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
75 switch err.ColumnName { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
76 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
|
77 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
|
78 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
79 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
|
80 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
|
81 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
82 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
|
83 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
|
84 return |
4062
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 } |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
87 } |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
88 case foreignKeyViolation: |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
89 switch err.SchemaName { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
90 case "waterway": |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
91 switch err.TableName { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
92 case "gauge_measurements", "gauge_predictions", "bottlenecks": |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
93 switch err.ConstraintName { |
4442
49aa67fb2b6d
Improve error message if predictions reference no valid gauge
Tom Gottfried <tom@intevation.de>
parents:
4441
diff
changeset
|
94 case "waterway_bottlenecks_reference_gauge", |
49aa67fb2b6d
Improve error message if predictions reference no valid gauge
Tom Gottfried <tom@intevation.de>
parents:
4441
diff
changeset
|
95 "waterway_gauge_measurements_reference_gauge", |
49aa67fb2b6d
Improve error message if predictions reference no valid gauge
Tom Gottfried <tom@intevation.de>
parents:
4441
diff
changeset
|
96 "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
|
97 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
|
98 return |
4062
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 } |
4941
df6c8a485979
Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents:
4884
diff
changeset
|
101 switch err.TableName { |
df6c8a485979
Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents:
4884
diff
changeset
|
102 case "fairway_marks_bcnlat_dirimps", |
df6c8a485979
Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents:
4884
diff
changeset
|
103 "fairway_marks_daymar_dirimps", |
df6c8a485979
Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents:
4884
diff
changeset
|
104 "fairway_marks_notmrk_dirimps": |
df6c8a485979
Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents:
4884
diff
changeset
|
105 switch err.ConstraintName { |
df6c8a485979
Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents:
4884
diff
changeset
|
106 case "fairway_marks_bcnlat_dirimps_dirimp_fkey", |
df6c8a485979
Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents:
4884
diff
changeset
|
107 "fairway_marks_daymar_dirimps_dirimp_fkey", |
df6c8a485979
Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents:
4884
diff
changeset
|
108 "fairway_marks_notmrk_dirimps_dirimp_fkey": |
df6c8a485979
Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents:
4884
diff
changeset
|
109 m = "Invalid value for dirimp" |
df6c8a485979
Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents:
4884
diff
changeset
|
110 return |
df6c8a485979
Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents:
4884
diff
changeset
|
111 } |
df6c8a485979
Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents:
4884
diff
changeset
|
112 } |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
113 } |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
114 case uniqueViolation: |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
115 switch err.SchemaName { |
4719
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
116 case "users": |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
117 switch err.TableName { |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
118 case "stretches": |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
119 switch err.ConstraintName { |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
120 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
|
121 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
|
122 c = http.StatusConflict |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
123 return |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
124 } |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
125 } |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
126 case "waterway": |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
127 switch err.TableName { |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
128 case "sections": |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
129 switch err.ConstraintName { |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
130 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
|
131 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
|
132 c = http.StatusConflict |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
133 return |
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
134 } |
5095
e21cbb9768a2
Prevent duplicate fairway areas
Tom Gottfried <tom@intevation.de>
parents:
5031
diff
changeset
|
135 case "fairway_dimensions": |
e21cbb9768a2
Prevent duplicate fairway areas
Tom Gottfried <tom@intevation.de>
parents:
5031
diff
changeset
|
136 switch err.ConstraintName { |
e21cbb9768a2
Prevent duplicate fairway areas
Tom Gottfried <tom@intevation.de>
parents:
5031
diff
changeset
|
137 case "fairway_dimensions_area_unique": |
5275
73563c4bba5b
Slight improvement of log messages for fd import.
wilde@azure1.rgb.intevation.de
parents:
5095
diff
changeset
|
138 m = "Duplicate fairway dimension area" |
5095
e21cbb9768a2
Prevent duplicate fairway areas
Tom Gottfried <tom@intevation.de>
parents:
5031
diff
changeset
|
139 c = http.StatusConflict |
e21cbb9768a2
Prevent duplicate fairway areas
Tom Gottfried <tom@intevation.de>
parents:
5031
diff
changeset
|
140 return |
e21cbb9768a2
Prevent duplicate fairway areas
Tom Gottfried <tom@intevation.de>
parents:
5031
diff
changeset
|
141 } |
4719
07e8436ef4de
Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
4442
diff
changeset
|
142 } |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
143 } |
4749
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
144 case exclusionViolation: |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
145 switch err.SchemaName { |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
146 case "waterway": |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
147 switch err.TableName { |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
148 case "sections": |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
149 switch err.ConstraintName { |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
150 case "sections_name_country_excl": |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
151 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
|
152 c = http.StatusConflict |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
153 return |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
154 } |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
155 } |
fd9f171b87e4
Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents:
4723
diff
changeset
|
156 } |
4181
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
157 case checkViolation: |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
158 switch err.SchemaName { |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
159 case "waterway": |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
160 switch err.TableName { |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
161 case "sounding_results": |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
162 switch err.ConstraintName { |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
163 case "b_sounding_results_in_bn_area": |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
164 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
|
165 c = http.StatusConflict |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
166 return |
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
167 } |
5031
8c590ef35280
Improve feedback if geometry cannot be stored
Tom Gottfried <tom@intevation.de>
parents:
4941
diff
changeset
|
168 case "fairway_dimensions": |
8c590ef35280
Improve feedback if geometry cannot be stored
Tom Gottfried <tom@intevation.de>
parents:
4941
diff
changeset
|
169 switch err.ConstraintName { |
8c590ef35280
Improve feedback if geometry cannot be stored
Tom Gottfried <tom@intevation.de>
parents:
4941
diff
changeset
|
170 case "fairway_dimensions_area_check": |
8c590ef35280
Improve feedback if geometry cannot be stored
Tom Gottfried <tom@intevation.de>
parents:
4941
diff
changeset
|
171 m = "Geometry could not be stored as valid, non-empty polygon" |
8c590ef35280
Improve feedback if geometry cannot be stored
Tom Gottfried <tom@intevation.de>
parents:
4941
diff
changeset
|
172 return |
8c590ef35280
Improve feedback if geometry cannot be stored
Tom Gottfried <tom@intevation.de>
parents:
4941
diff
changeset
|
173 } |
4181
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
174 } |
4884
de12c9af3abf
Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents:
4871
diff
changeset
|
175 case "internal": |
de12c9af3abf
Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents:
4871
diff
changeset
|
176 switch err.TableName { |
de12c9af3abf
Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents:
4871
diff
changeset
|
177 case "user_profiles": |
de12c9af3abf
Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents:
4871
diff
changeset
|
178 switch err.ConstraintName { |
de12c9af3abf
Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents:
4871
diff
changeset
|
179 case "user_profiles_username_check": |
de12c9af3abf
Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents:
4871
diff
changeset
|
180 m = "User name too long" |
de12c9af3abf
Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents:
4871
diff
changeset
|
181 c = http.StatusBadRequest |
de12c9af3abf
Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents:
4871
diff
changeset
|
182 return |
de12c9af3abf
Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents:
4871
diff
changeset
|
183 } |
de12c9af3abf
Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents:
4871
diff
changeset
|
184 } |
4181
bd97dc2dceea
Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents:
4175
diff
changeset
|
185 } |
4723
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
186 case duplicateObject: |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
187 switch { |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
188 case strings.Contains(recent, "CREATE ROLE"): |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
189 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
|
190 c = http.StatusConflict |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
191 return |
baabc2b2f094
Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents:
4719
diff
changeset
|
192 } |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
193 case noDataFound: |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
194 switch { |
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
195 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
|
196 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
|
197 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
198 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
|
199 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
|
200 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
201 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
|
202 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
|
203 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
204 } |
4871 | 205 case insufficientPrivilege: |
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
|
206 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
|
207 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
208 } |
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
|
209 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
|
210 return |
4062
6c760abcff0e
Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
211 } |