Caps-Server/Sources/App/Error.swift

38 lines
757 B
Swift
Raw Normal View History

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 {
case unknownId
case invalidBody
case dataInconsistency
case invalidFile
2021-11-08 21:58:55 +01:00
case invalidConfiguration
case invalidData
2020-05-19 15:19:19 +02:00
var response: HTTPResponseStatus {
switch self {
2020-09-20 12:36:10 +02:00
/// 404
2020-05-19 15:19:19 +02:00
case .unknownId: return .notFound
2020-09-20 12:36:10 +02:00
/// 400
2020-05-19 15:19:19 +02:00
case .invalidBody: return .badRequest
/// 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
2020-05-19 15:19:19 +02:00
}
}
}