Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/errors.py
# Copyright (C) 2017 The Software Heritage developers | # Copyright (C) 2017-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
"""Module in charge of providing the standard sword errors | """Module in charge of providing the standard sword errors | ||||
""" | """ | ||||
from rest_framework import status | from rest_framework import status | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
FORBIDDEN = 'forbidden' | FORBIDDEN = 'forbidden' | ||||
UNAUTHORIZED = 'unauthorized' | UNAUTHORIZED = 'unauthorized' | ||||
NOT_FOUND = 'unknown' | NOT_FOUND = 'unknown' | ||||
BAD_REQUEST = 'bad-request' | BAD_REQUEST = 'bad-request' | ||||
ERROR_CONTENT = 'error-content' | ERROR_CONTENT = 'error-content' | ||||
CHECKSUM_MISMATCH = 'checksum-mismatch' | CHECKSUM_MISMATCH = 'checksum-mismatch' | ||||
MEDIATION_NOT_ALLOWED = 'mediation-not-allowed' | MEDIATION_NOT_ALLOWED = 'mediation-not-allowed' | ||||
METHOD_NOT_ALLOWED = 'method-not-allowed' | METHOD_NOT_ALLOWED = 'method-not-allowed' | ||||
MAX_UPLOAD_SIZE_EXCEEDED = 'max_upload_size_exceeded' | MAX_UPLOAD_SIZE_EXCEEDED = 'max_upload_size_exceeded' | ||||
PARSING_ERROR = 'parsing-error' | |||||
class ParserError(ValueError): | |||||
"""Specific parsing error detected when parsing the xml metadata input | |||||
""" | |||||
pass | |||||
ERRORS = { | ERRORS = { | ||||
FORBIDDEN: { | FORBIDDEN: { | ||||
'status': status.HTTP_403_FORBIDDEN, | 'status': status.HTTP_403_FORBIDDEN, | ||||
'iri': 'http://purl.org/net/sword/error/ErrorForbidden', | 'iri': 'http://purl.org/net/sword/error/ErrorForbidden', | ||||
'tag': 'sword:ErrorForbidden', | 'tag': 'sword:ErrorForbidden', | ||||
}, | }, | ||||
Show All 17 Lines | CHECKSUM_MISMATCH: { | ||||
'iri': 'http://purl.org/net/sword/error/ErrorChecksumMismatch', | 'iri': 'http://purl.org/net/sword/error/ErrorChecksumMismatch', | ||||
'tag': 'sword:ErrorChecksumMismatch', | 'tag': 'sword:ErrorChecksumMismatch', | ||||
}, | }, | ||||
BAD_REQUEST: { | BAD_REQUEST: { | ||||
'status': status.HTTP_400_BAD_REQUEST, | 'status': status.HTTP_400_BAD_REQUEST, | ||||
'iri': 'http://purl.org/net/sword/error/ErrorBadRequest', | 'iri': 'http://purl.org/net/sword/error/ErrorBadRequest', | ||||
'tag': 'sword:ErrorBadRequest', | 'tag': 'sword:ErrorBadRequest', | ||||
}, | }, | ||||
PARSING_ERROR: { | |||||
'status': status.HTTP_400_BAD_REQUEST, | |||||
'iri': 'http://purl.org/net/sword/error/ErrorBadRequest', | |||||
'tag': 'sword:ErrorBadRequest', | |||||
}, | |||||
MEDIATION_NOT_ALLOWED: { | MEDIATION_NOT_ALLOWED: { | ||||
'status': status.HTTP_412_PRECONDITION_FAILED, | 'status': status.HTTP_412_PRECONDITION_FAILED, | ||||
'iri': 'http://purl.org/net/sword/error/MediationNotAllowed', | 'iri': 'http://purl.org/net/sword/error/MediationNotAllowed', | ||||
'tag': 'sword:MediationNotAllowed', | 'tag': 'sword:MediationNotAllowed', | ||||
}, | }, | ||||
METHOD_NOT_ALLOWED: { | METHOD_NOT_ALLOWED: { | ||||
'status': status.HTTP_405_METHOD_NOT_ALLOWED, | 'status': status.HTTP_405_METHOD_NOT_ALLOWED, | ||||
'iri': 'http://purl.org/net/sword/error/MethodNotAllowed', | 'iri': 'http://purl.org/net/sword/error/MethodNotAllowed', | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |