#!/usr/bin/env python3
# Author(s): Toni Sissala
# Copyright 2020 Finnish Social Science Data Archive FSD / University of Tampere
# Licensed under the EUPL. See LICENSE.txt for full license.
"""Errors for OAI-protocol
"""
[docs]class OAIError(Exception):
"""Base for OAI errors
"""
code_ = None
def __init__(self, msg=None, context=None):
super().__init__(msg)
if msg:
self.msg = msg
self.context = context
def __str__(self):
_str = "{}: {}".format(self.get_code(), self.get_msg())
if self.context:
_str += " [{}]".format(self.get_context())
return _str
def __repr__(self):
return str(self.code_)
[docs] def get_code(self):
"""Get OAI error code"""
return self.code_
[docs] def get_msg(self):
"""Get OAI error message"""
return self.msg
[docs] def get_context(self):
"""Get error context"""
return self.context
[docs] def get_contextual_message(self):
"""Get error message with possible context.
:returns: message with context.
:rtype: str
"""
msg = self.get_msg()
ctx = self.get_context()
if ctx is not None:
msg = "%s: %s" % (msg, ctx)
return msg
[docs]class MissingVerb(OAIError):
"""OAIError for missing verb"""
code_ = 'badVerb'
msg = 'Missing verb'
[docs]class BadVerb(OAIError):
"""OAIError for bad verb"""
code_ = 'badVerb'
msg = 'Invalid verb'
[docs]class IdDoesNotExist(OAIError):
"""OAIError for no such id"""
code_ = 'idDoesNotExist'
msg = 'Identifier maps to no known item'
[docs]class BadArgument(OAIError):
"""OAIError for bad argument"""
code_ = 'badArgument'
msg = 'Illegal or missing argument'
[docs]class NoRecordsMatch(OAIError):
"""OAIError for no records match"""
code_ = 'noRecordsMatch'
msg = 'Could not find records matching harvesting criteria'
[docs]class BadResumptionToken(OAIError):
"""OAIError for bad resumption token"""
code_ = 'badResumptionToken'
msg = ('Unable to resume harvesting with incomplete lists due to possible '
'changes in the repository. Harvester is advised to restart '
'the list request sequence.')
[docs]class NoSetHierarchy(OAIError):
"""OAIError for repositories not implementing sets"""
code_ = 'noSetHierarchy'
msg = 'This repository does not support sets'