Caps-Server/Sources/App/Error.swift

75 lines
1.2 KiB
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 {
2022-06-24 11:31:09 +02:00
/**
HTTP Code: 404
*/
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
*/
case invalidData
/**
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 {
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
case .serviceUnavailable: return .noContent
2020-05-19 15:19:19 +02:00
}
}
}