75 lines
1.2 KiB
Swift
75 lines
1.2 KiB
Swift
//
|
|
// Error.swift
|
|
// App
|
|
//
|
|
// Created by Christoph on 17.05.20.
|
|
//
|
|
|
|
import Foundation
|
|
import Vapor
|
|
|
|
enum CapError: Error {
|
|
|
|
/**
|
|
|
|
HTTP Code: 404
|
|
*/
|
|
case unknownId
|
|
|
|
/**
|
|
|
|
HTTP Code: 400
|
|
*/
|
|
case invalidBody
|
|
|
|
/**
|
|
|
|
HTTP Code: 409
|
|
*/
|
|
case dataInconsistency
|
|
|
|
/**
|
|
|
|
HTTP Code: 412
|
|
*/
|
|
case invalidFile
|
|
|
|
/**
|
|
|
|
HTTP Code: 500
|
|
*/
|
|
case invalidConfiguration
|
|
|
|
/**
|
|
|
|
HTTP Code: 406
|
|
*/
|
|
case invalidData
|
|
|
|
/**
|
|
The server failed to initialize the data and is not operational
|
|
|
|
HTTP Code: 204
|
|
*/
|
|
case serviceUnavailable
|
|
|
|
var response: HTTPResponseStatus {
|
|
switch self {
|
|
/// 404
|
|
case .unknownId: return .notFound
|
|
/// 400
|
|
case .invalidBody: return .badRequest
|
|
/// 406
|
|
case .invalidData: return .notAcceptable
|
|
/// 409
|
|
case .dataInconsistency: return .conflict
|
|
/// 412
|
|
case .invalidFile: return .preconditionFailed
|
|
/// 500
|
|
case .invalidConfiguration: return .internalServerError
|
|
case .serviceUnavailable: return .noContent
|
|
}
|
|
}
|
|
}
|
|
|