annotate pkg/pgxutils/errors.go @ 4884:de12c9af3abf

Add readable error for too long user names
author Tom Gottfried <tom@intevation.de>
date Mon, 03 Feb 2020 15:02:49 +0100
parents 4d8982fa49f9
children df6c8a485979
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4d8982fa49f9 Restore naming scheme
Tom Gottfried <tom@intevation.de>
parents: 4749
diff changeset
25 // camel cased condition name = error code
4d8982fa49f9 Restore naming scheme
Tom Gottfried <tom@intevation.de>
parents: 4749
diff changeset
26 // from appendix A of PostgreSQL documentation
4d8982fa49f9 Restore naming scheme
Tom Gottfried <tom@intevation.de>
parents: 4749
diff changeset
27 notNullViolation = "23502"
4d8982fa49f9 Restore naming scheme
Tom Gottfried <tom@intevation.de>
parents: 4749
diff changeset
28 foreignKeyViolation = "23503"
4d8982fa49f9 Restore naming scheme
Tom Gottfried <tom@intevation.de>
parents: 4749
diff changeset
29 uniqueViolation = "23505"
4d8982fa49f9 Restore naming scheme
Tom Gottfried <tom@intevation.de>
parents: 4749
diff changeset
30 checkViolation = "23514"
4d8982fa49f9 Restore naming scheme
Tom Gottfried <tom@intevation.de>
parents: 4749
diff changeset
31 exclusionViolation = "23P01"
4d8982fa49f9 Restore naming scheme
Tom Gottfried <tom@intevation.de>
parents: 4749
diff changeset
32 insufficientPrivilege = "42501"
4d8982fa49f9 Restore naming scheme
Tom Gottfried <tom@intevation.de>
parents: 4749
diff changeset
33 duplicateObject = "42710"
4d8982fa49f9 Restore naming scheme
Tom Gottfried <tom@intevation.de>
parents: 4749
diff changeset
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 }
6c760abcff0e Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
101 }
6c760abcff0e Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
102 case uniqueViolation:
6c760abcff0e Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
103 switch err.SchemaName {
4719
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
104 case "users":
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
105 switch err.TableName {
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
106 case "stretches":
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
107 switch err.ConstraintName {
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
108 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
109 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
110 c = http.StatusConflict
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
111 return
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
112 }
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
113 }
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
114 case "waterway":
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
115 switch err.TableName {
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
116 case "sections":
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
117 switch err.ConstraintName {
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
118 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
119 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
120 c = http.StatusConflict
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
121 return
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
122 }
07e8436ef4de Improve error messages for name conflicts with sections and stretches
Tom Gottfried <tom@intevation.de>
parents: 4442
diff changeset
123 }
4062
6c760abcff0e Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
124 }
4749
fd9f171b87e4 Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents: 4723
diff changeset
125 case exclusionViolation:
fd9f171b87e4 Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents: 4723
diff changeset
126 switch err.SchemaName {
fd9f171b87e4 Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents: 4723
diff changeset
127 case "waterway":
fd9f171b87e4 Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents: 4723
diff changeset
128 switch err.TableName {
fd9f171b87e4 Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents: 4723
diff changeset
129 case "sections":
fd9f171b87e4 Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents: 4723
diff changeset
130 switch err.ConstraintName {
fd9f171b87e4 Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents: 4723
diff changeset
131 case "sections_name_country_excl":
fd9f171b87e4 Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents: 4723
diff changeset
132 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
133 c = http.StatusConflict
fd9f171b87e4 Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents: 4723
diff changeset
134 return
fd9f171b87e4 Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents: 4723
diff changeset
135 }
fd9f171b87e4 Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents: 4723
diff changeset
136 }
fd9f171b87e4 Generally disallow the same section name for different countries
Tom Gottfried <tom@intevation.de>
parents: 4723
diff changeset
137 }
4181
bd97dc2dceea Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents: 4175
diff changeset
138 case checkViolation:
bd97dc2dceea Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents: 4175
diff changeset
139 switch err.SchemaName {
bd97dc2dceea Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents: 4175
diff changeset
140 case "waterway":
bd97dc2dceea Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents: 4175
diff changeset
141 switch err.TableName {
bd97dc2dceea Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents: 4175
diff changeset
142 case "sounding_results":
bd97dc2dceea Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents: 4175
diff changeset
143 switch err.ConstraintName {
bd97dc2dceea Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents: 4175
diff changeset
144 case "b_sounding_results_in_bn_area":
bd97dc2dceea Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents: 4175
diff changeset
145 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
146 c = http.StatusConflict
bd97dc2dceea Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents: 4175
diff changeset
147 return
bd97dc2dceea Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents: 4175
diff changeset
148 }
bd97dc2dceea Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents: 4175
diff changeset
149 }
4884
de12c9af3abf Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents: 4871
diff changeset
150 case "internal":
de12c9af3abf Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents: 4871
diff changeset
151 switch err.TableName {
de12c9af3abf Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents: 4871
diff changeset
152 case "user_profiles":
de12c9af3abf Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents: 4871
diff changeset
153 switch err.ConstraintName {
de12c9af3abf Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents: 4871
diff changeset
154 case "user_profiles_username_check":
de12c9af3abf Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents: 4871
diff changeset
155 m = "User name too long"
de12c9af3abf Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents: 4871
diff changeset
156 c = http.StatusBadRequest
de12c9af3abf Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents: 4871
diff changeset
157 return
de12c9af3abf Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents: 4871
diff changeset
158 }
de12c9af3abf Add readable error for too long user names
Tom Gottfried <tom@intevation.de>
parents: 4871
diff changeset
159 }
4181
bd97dc2dceea Add readable error message for SR import
Tom Gottfried <tom@intevation.de>
parents: 4175
diff changeset
160 }
4723
baabc2b2f094 Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents: 4719
diff changeset
161 case duplicateObject:
baabc2b2f094 Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents: 4719
diff changeset
162 switch {
baabc2b2f094 Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents: 4719
diff changeset
163 case strings.Contains(recent, "CREATE ROLE"):
baabc2b2f094 Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents: 4719
diff changeset
164 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
165 c = http.StatusConflict
baabc2b2f094 Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents: 4719
diff changeset
166 return
baabc2b2f094 Avoid creating user profiles without matching role
Tom Gottfried <tom@intevation.de>
parents: 4719
diff changeset
167 }
4062
6c760abcff0e Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
168 case noDataFound:
6c760abcff0e Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
169 switch {
6c760abcff0e Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
170 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
171 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
172 return
4062
6c760abcff0e Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
173 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
174 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
175 return
4062
6c760abcff0e Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
176 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
177 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
178 return
4062
6c760abcff0e Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
179 }
4871
4d8982fa49f9 Restore naming scheme
Tom Gottfried <tom@intevation.de>
parents: 4749
diff changeset
180 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
181 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
182 return
4062
6c760abcff0e Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
183 }
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
184 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
185 return
4062
6c760abcff0e Move handling of PostgreSQL errors to own package
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
186 }