Debian Codegraph @

ncbi_acc_download/errors.py

raw
1 # Copyright 2017,2018 Kai Blin
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Custom error classes of the ncbi-by-accession downloader."""
15
16
17 class DownloadError(RuntimeError):
18 """Base error for all problems when downloading from NCBI."""
19
20 pass
21
22
23 class InvalidIdError(RuntimeError):
24 """Error thrown when Entrez responds with a 4xx error (other than 429)."""
25
26 def __init__(self, message, ids, status_code):
27 super().__init__(message)
28 self.ids = ids
29 self.status_code = status_code
30
31
32 class TooManyRequests(DownloadError):
33 """Error thrown when Entrez responds with a 429 error."""
34
35 def __init__(self, message, retry_after):
36 super().__init__(message)
37 self.retry_after = retry_after
38
39
40 class BadPatternError(DownloadError):
41 """Error thrown when download file contains an error pattern."""
42
43 pass
44
45
46 class ValidationError(DownloadError):
47 """Error thrown when download file failes extended validation."""
48
49 pass