@@ -135,6 +135,84 @@ def _bibliography_headers(obj_or_list, code, many=False):
135
135
"application/linkset+json" : ResponseHandler (FAIRSignpostingProfileLvl2Serializer ()),
136
136
}
137
137
138
+ error_handlers = {
139
+ ** ErrorHandlersMixin .error_handlers ,
140
+ DeserializerError : create_error_handler (
141
+ lambda exc : HTTPJSONException (
142
+ code = 400 ,
143
+ description = exc .args [0 ],
144
+ )
145
+ ),
146
+ StyleNotFoundError : create_error_handler (
147
+ HTTPJSONException (
148
+ code = 400 ,
149
+ description = _ ("Citation string style not found." ),
150
+ )
151
+ ),
152
+ ReviewNotFoundError : create_error_handler (
153
+ HTTPJSONException (
154
+ code = 404 ,
155
+ description = _ ("Review for draft not found" ),
156
+ )
157
+ ),
158
+ ReviewStateError : create_error_handler (
159
+ lambda e : HTTPJSONException (
160
+ code = 400 ,
161
+ description = str (e ),
162
+ )
163
+ ),
164
+ ReviewExistsError : create_error_handler (
165
+ lambda e : HTTPJSONException (
166
+ code = 400 ,
167
+ description = str (e ),
168
+ )
169
+ ),
170
+ InvalidRelationValue : create_error_handler (
171
+ lambda exc : HTTPJSONException (
172
+ code = 400 ,
173
+ description = exc .args [0 ],
174
+ )
175
+ ),
176
+ InvalidAccessRestrictions : create_error_handler (
177
+ lambda exc : HTTPJSONException (
178
+ code = 400 ,
179
+ description = exc .args [0 ],
180
+ )
181
+ ),
182
+ ValidationErrorWithMessageAsList : create_error_handler (
183
+ lambda e : HTTPJSONValidationWithMessageAsListException (e )
184
+ ),
185
+ AccessRequestExistsError : create_error_handler (
186
+ lambda e : HTTPJSONException (
187
+ code = 400 ,
188
+ description = e .description ,
189
+ )
190
+ ),
191
+ RecordDeletedException : create_error_handler (
192
+ lambda e : (
193
+ HTTPJSONException (code = 404 , description = _ ("Record not found" ))
194
+ if not e .record .tombstone .is_visible
195
+ else HTTPJSONException (
196
+ code = 410 ,
197
+ description = _ ("Record deleted" ),
198
+ tombstone = e .record .tombstone .dump (),
199
+ )
200
+ )
201
+ ),
202
+ RecordSubmissionClosedCommunityError : create_error_handler (
203
+ lambda e : HTTPJSONException (
204
+ code = 403 ,
205
+ description = e .description ,
206
+ )
207
+ ),
208
+ CommunityRequiredError : create_error_handler (
209
+ HTTPJSONException (
210
+ code = 400 ,
211
+ description = _ ("Cannot publish without selecting a community." ),
212
+ )
213
+ ),
214
+ }
215
+
138
216
139
217
#
140
218
# Records and record versions
@@ -187,83 +265,10 @@ class RDMRecordResourceConfig(RecordResourceConfig, ConfiguratorMixin):
187
265
default = record_serializers ,
188
266
)
189
267
190
- error_handlers = {
191
- ** ErrorHandlersMixin .error_handlers ,
192
- DeserializerError : create_error_handler (
193
- lambda exc : HTTPJSONException (
194
- code = 400 ,
195
- description = exc .args [0 ],
196
- )
197
- ),
198
- StyleNotFoundError : create_error_handler (
199
- HTTPJSONException (
200
- code = 400 ,
201
- description = _ ("Citation string style not found." ),
202
- )
203
- ),
204
- ReviewNotFoundError : create_error_handler (
205
- HTTPJSONException (
206
- code = 404 ,
207
- description = _ ("Review for draft not found" ),
208
- )
209
- ),
210
- ReviewStateError : create_error_handler (
211
- lambda e : HTTPJSONException (
212
- code = 400 ,
213
- description = str (e ),
214
- )
215
- ),
216
- ReviewExistsError : create_error_handler (
217
- lambda e : HTTPJSONException (
218
- code = 400 ,
219
- description = str (e ),
220
- )
221
- ),
222
- InvalidRelationValue : create_error_handler (
223
- lambda exc : HTTPJSONException (
224
- code = 400 ,
225
- description = exc .args [0 ],
226
- )
227
- ),
228
- InvalidAccessRestrictions : create_error_handler (
229
- lambda exc : HTTPJSONException (
230
- code = 400 ,
231
- description = exc .args [0 ],
232
- )
233
- ),
234
- ValidationErrorWithMessageAsList : create_error_handler (
235
- lambda e : HTTPJSONValidationWithMessageAsListException (e )
236
- ),
237
- AccessRequestExistsError : create_error_handler (
238
- lambda e : HTTPJSONException (
239
- code = 400 ,
240
- description = e .description ,
241
- )
242
- ),
243
- RecordDeletedException : create_error_handler (
244
- lambda e : (
245
- HTTPJSONException (code = 404 , description = _ ("Record not found" ))
246
- if not e .record .tombstone .is_visible
247
- else HTTPJSONException (
248
- code = 410 ,
249
- description = _ ("Record deleted" ),
250
- tombstone = e .record .tombstone .dump (),
251
- )
252
- )
253
- ),
254
- RecordSubmissionClosedCommunityError : create_error_handler (
255
- lambda e : HTTPJSONException (
256
- code = 403 ,
257
- description = e .description ,
258
- )
259
- ),
260
- CommunityRequiredError : create_error_handler (
261
- HTTPJSONException (
262
- code = 400 ,
263
- description = _ ("Cannot publish without selecting a community." ),
264
- )
265
- ),
266
- }
268
+ error_handlers = FromConfig (
269
+ "RDM_RECORDS_ERROR_HANDLERS" ,
270
+ default = error_handlers ,
271
+ )
267
272
268
273
269
274
#
0 commit comments