libreoffice-online/loolwsd/Exceptions.hpp
Ashod Nakashian 33854ec4ac loolwsd: cleanup and improve WSD request handlers
Standardized error handling in request-handlers.

There is a new family of internal exeptions designed
to signify the type of error and how to handle it.
All handlers must throw one of those errors
and they will be translated to the correct HTTP
response when caught.

Since some requests send a response as part of their
handling (convert-to, for example) those handlers
must return a flag signlaning whether or not they
sent a response. If not, HTTP OK response is sent
at the end of the handler.

To complicate things, some requests upgrade the
connection to WebSocket. In those cases errors
must be sent via the WebSocket and not as an
HTTP response. The error message sent can (and
in most cases should) be displayed to the end-user.

A new file, UserMessages.hpp, has been added to
hold user-visible messages that can be
reviewed and translated.

Change-Id: Icc725f3313446d4514cf6d092635158ee7171f5d
Reviewed-on: https://gerrit.libreoffice.org/24133
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-16 17:56:55 +00:00

52 lines
1.4 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* 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/.
*/
// Exception classes to differentiate between the
// different error situations and handling.
#ifndef INCLUDED_EXCEPTIONS_HPP
#define INCLUDED_EXCEPTIONS_HPP
#include <exception>
// Generic LOOL errors and base for others.
class LoolException : public std::runtime_error
{
protected:
using std::runtime_error::runtime_error;
};
/// A bad-request exception that is means to signify,
/// and translate into, an HTTP bad request.
class BadRequestException : public LoolException
{
public:
using LoolException::LoolException;
};
/// An authorization exception that is means to signify,
/// and translate into, an HTTP unauthorized error.
class UnauthorizedRequestException : public LoolException
{
public:
using LoolException::LoolException;
};
/// An generic error-message exception meant to
/// propagate via a valid WebSocket to the client.
/// The contents of what() will be displayed on screen.
class WebSocketErrorMessageException : public LoolException
{
public:
using LoolException::LoolException;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */