2020-05-19 15:19:19 +02:00
|
|
|
//
|
|
|
|
// Error.swift
|
|
|
|
// App
|
|
|
|
//
|
|
|
|
// Created by Christoph on 17.05.20.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Vapor
|
|
|
|
|
|
|
|
enum CapError: Error {
|
|
|
|
|
2022-06-24 11:31:09 +02:00
|
|
|
/**
|
|
|
|
|
2023-02-17 12:27:08 +01:00
|
|
|
HTTP Code: 410
|
2022-06-24 11:31:09 +02:00
|
|
|
*/
|
2020-05-19 15:19:19 +02:00
|
|
|
case unknownId
|
2022-06-24 11:31:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
HTTP Code: 400
|
|
|
|
*/
|
2020-05-19 15:19:19 +02:00
|
|
|
case invalidBody
|
2022-06-24 11:31:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
HTTP Code: 409
|
|
|
|
*/
|
2020-05-19 15:19:19 +02:00
|
|
|
case dataInconsistency
|
2022-06-24 11:31:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
HTTP Code: 412
|
|
|
|
*/
|
2020-05-19 15:19:19 +02:00
|
|
|
case invalidFile
|
2022-06-24 11:31:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
HTTP Code: 500
|
|
|
|
*/
|
2021-11-08 21:58:55 +01:00
|
|
|
case invalidConfiguration
|
2022-06-24 11:31:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
HTTP Code: 406
|
|
|
|
*/
|
2022-05-28 21:59:32 +02:00
|
|
|
case invalidData
|
2023-01-17 22:02:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
The server failed to initialize the data and is not operational
|
|
|
|
|
|
|
|
HTTP Code: 204
|
|
|
|
*/
|
|
|
|
case serviceUnavailable
|
2020-05-19 15:19:19 +02:00
|
|
|
|
|
|
|
var response: HTTPResponseStatus {
|
|
|
|
switch self {
|
2023-02-17 12:27:08 +01:00
|
|
|
/// 410
|
|
|
|
case .unknownId: return .gone
|
2020-09-20 12:36:10 +02:00
|
|
|
/// 400
|
2020-05-19 15:19:19 +02:00
|
|
|
case .invalidBody: return .badRequest
|
2022-05-28 21:59:32 +02:00
|
|
|
/// 406
|
|
|
|
case .invalidData: return .notAcceptable
|
2020-09-20 12:36:10 +02:00
|
|
|
/// 409
|
2020-05-19 15:19:19 +02:00
|
|
|
case .dataInconsistency: return .conflict
|
2020-09-20 12:36:10 +02:00
|
|
|
/// 412
|
2020-05-19 15:19:19 +02:00
|
|
|
case .invalidFile: return .preconditionFailed
|
2021-11-08 21:58:55 +01:00
|
|
|
/// 500
|
|
|
|
case .invalidConfiguration: return .internalServerError
|
2023-01-17 22:02:27 +01:00
|
|
|
case .serviceUnavailable: return .noContent
|
2020-05-19 15:19:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|