| 1 | import { HttpStatus } from '@nestjs/common'; |
| 2 | |
| 3 | import { DomainError } |
| 4 | |
| 5 | /** GitHub's NOT_FOUND, worded as GitHub words it, e.g. "Could not resolve to a Repository with the name 'o/r'." */ |
| 6 | export class CouldNotResolveError |
| 7 | readonly status = |
| 8 | } |
| 9 | |
| 10 | export class BadCredentialsError |
| 11 | readonly status = |
| 12 | |
| 13 | constructor() { |
| 14 | super('Bad credentials'); |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | export class RequiresAuthenticationError |
| 19 | readonly status = |
| 20 | |
| 21 | constructor() { |
| 22 | super('Requires authentication'); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | export class GithubForbiddenError |
| 27 | readonly status = |
| 28 | } |
| 29 | |
| 30 | export class UnprocessableError |
| 31 | readonly status = |
| 32 | } |
| 33 | |
| 34 | export class InsufficientScopesError |
| 35 | readonly status = |
| 36 | |
| 37 | constructor( |
| 38 | field: string, |
| 39 | readonly accepted: |
| 40 | granted: readonly |
| 41 | ) { |
| 42 | super( |
| 43 | `Your token has not been granted the required scopes to execute this query. The '${field}' field requires one of the following scopes: [${ |
| 44 | ); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | export type ValidationFailure |
| 49 | resource: string |
| 50 | field: string |
| 51 | code: 'missing_field |
| 52 | }; |
| 53 | |
| 54 | /** GitHub REST's 422 "Validation Failed" with the fields that failed, as `errors` in the body. */ |
| 55 | export class GithubValidationError |
| 56 | readonly status = |
| 57 | |
| 58 | constructor(readonly errors |
| 59 | super('Validation Failed'); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /** GitHub's REST 404, worded "Not Found" whatever was missing, so a private resource and a missing one read the same. */ |
| 64 | export class GithubNotFoundError |
| 65 | readonly status = |
| 66 | |
| 67 | constructor() { |
| 68 | super('Not Found'); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | export class GithubConflictError |
| 73 | readonly status = |
| 74 | } |
| 75 | |
| 76 | /** GitHub answers every merge it will not make with 405. */ |
| 77 | export class NotMergeableError |
| 78 | readonly status = |
| 79 | |
| 80 | constructor() { |
| 81 | super('Pull Request is not mergeable'); |
| 82 | } |
| 83 | } |