Files
planka/server/api/responses/forbidden.js

73 lines
1.4 KiB
JavaScript
Raw Normal View History

/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
/**
* forbidden.js
*
* A custom response.
*
* Example usage:
* ```
* return res.forbidden();
* // -or-
* return res.forbidden(optionalData);
* ```
*
* Or with actions2:
* ```
* exits: {
* somethingHappened: {
* responseType: 'forbidden'
* }
* }
* ```
*
* ```
* throw 'somethingHappened';
* // -or-
* throw { somethingHappened: optionalData }
* ```
*/
2025-09-08 16:20:27 +02:00
/**
* @swagger
* components:
* responses:
* Forbidden:
* description: Access forbidden - insufficient permissions
* content:
* application/json:
* schema:
* type: object
* required:
* - code
* - message
* properties:
* code:
* type: string
* description: Error code
* example: E_FORBIDDEN
* message:
* type: string
* description: Error message
* example: Not enough rights
*/
module.exports = function forbidden(message) {
const { res } = this;
2025-08-21 15:10:02 +02:00
const data = {
code: 'E_FORBIDDEN',
2025-08-21 15:10:02 +02:00
};
if (_.isPlainObject(message)) {
Object.assign(data, message);
} else {
data.message = message;
}
return res.status(403).json(data);
};