2016-04-16 18:56:23 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
2023-10-30 22:58:54 +01:00
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
2023-11-09 19:23:00 +01:00
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2016-04-16 18:56:23 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Exception classes to differentiate between the
|
|
|
|
// different error situations and handling.
|
2020-04-18 10:39:50 +02:00
|
|
|
|
|
|
|
#pragma once
|
2016-04-16 18:56:23 +02:00
|
|
|
|
2022-02-02 20:07:19 +01:00
|
|
|
#include <atomic>
|
2016-10-30 02:15:00 +01:00
|
|
|
#include <stdexcept>
|
2022-02-02 20:07:19 +01:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
// not beautiful
|
|
|
|
#define EXCEPTION_DECL(type,parent_cl) \
|
|
|
|
class type : public parent_cl \
|
|
|
|
{ \
|
|
|
|
public: \
|
|
|
|
static std::atomic<size_t> count; \
|
|
|
|
type(const std::string &str) : parent_cl(str) \
|
|
|
|
{ type::count++; } \
|
|
|
|
};
|
2016-04-16 18:56:23 +02:00
|
|
|
|
2021-11-15 17:00:44 +01:00
|
|
|
// Generic COOL errors and base for others.
|
2021-11-18 13:08:14 +01:00
|
|
|
class CoolException : public std::runtime_error
|
2016-04-16 18:56:23 +02:00
|
|
|
{
|
2016-10-18 07:32:18 +02:00
|
|
|
public:
|
|
|
|
std::string toString() const
|
|
|
|
{
|
|
|
|
return what();
|
|
|
|
}
|
2016-04-16 18:56:23 +02:00
|
|
|
protected:
|
|
|
|
using std::runtime_error::runtime_error;
|
|
|
|
};
|
|
|
|
|
2022-02-02 20:07:19 +01:00
|
|
|
EXCEPTION_DECL(StorageSpaceLowException,CoolException)
|
2016-09-30 15:09:53 +02:00
|
|
|
|
2017-05-18 20:05:45 +02:00
|
|
|
/// General exception thrown when we are not able to
|
|
|
|
/// connect to storage.
|
2022-02-02 20:07:19 +01:00
|
|
|
EXCEPTION_DECL(StorageConnectionException,CoolException)
|
2017-05-18 20:05:45 +02:00
|
|
|
|
2016-05-15 23:50:32 +02:00
|
|
|
/// A bad-request exception that is meant to signify,
|
2016-04-16 18:56:23 +02:00
|
|
|
/// and translate into, an HTTP bad request.
|
2022-02-02 20:07:19 +01:00
|
|
|
EXCEPTION_DECL(BadRequestException,CoolException)
|
2016-04-16 18:56:23 +02:00
|
|
|
|
2016-05-15 23:50:32 +02:00
|
|
|
/// A bad-argument exception that is meant to signify,
|
|
|
|
/// and translate into, an HTTP bad request.
|
2022-02-02 20:07:19 +01:00
|
|
|
EXCEPTION_DECL(BadArgumentException,BadRequestException)
|
2016-05-15 23:50:32 +02:00
|
|
|
|
2017-05-15 04:59:58 +02:00
|
|
|
/// An authorization exception that is meant to signify,
|
2016-04-16 18:56:23 +02:00
|
|
|
/// and translate into, an HTTP unauthorized error.
|
2022-02-02 20:07:19 +01:00
|
|
|
EXCEPTION_DECL(UnauthorizedRequestException,CoolException)
|
2016-04-16 18:56:23 +02:00
|
|
|
|
2017-05-15 04:58:02 +02:00
|
|
|
/// A service-unavailable exception that is meant to signify
|
|
|
|
/// an internal error.
|
2022-02-02 20:07:19 +01:00
|
|
|
EXCEPTION_DECL(ServiceUnavailableException,CoolException)
|
2019-06-22 12:26:42 +02:00
|
|
|
|
|
|
|
/// Badly formed data we are parsing
|
2022-02-02 20:07:19 +01:00
|
|
|
EXCEPTION_DECL(ParseError,CoolException)
|
2019-06-22 12:26:42 +02:00
|
|
|
|
2016-04-16 18:56:23 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|