How to use the http-status-codes.FORBIDDEN function in http-status-codes

To help you get started, we’ve selected a few http-status-codes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github re-figure / refigure / back / figures.js View on Github external
db.pool.query('SELECT * FROM Metapublication WHERE ID = ?', [req.body.MetapublicationID], (err, results) => {
        if (err) {
            console.log('Failed to determine Metapublication while new Figure creation', err);
            return rfUtils.error(res, httpStatus.INTERNAL_SERVER_ERROR, constants.ERROR_SQL, 'Failed to identify Metapublication');
        }
        if (results.length === 0) {
            return rfUtils.error(res, httpStatus.NOT_FOUND, constants.ERROR_SQLNOTFOUND, 'Metapublication is not found');
        }
        if (!auth.checkObjectAccess(req, results[0].UserID)) {
            return rfUtils.error(res, httpStatus.FORBIDDEN, constants.ERROR_FORBIDDEN, constants.ERROR_MSG_FORBIDDEN);
        }
        upd[db.model.ID] = uuid.v1();
        upd['UserID'] = req.User.ID;
        upd['MetapublicationID'] = req.body.MetapublicationID;

        let params = [];
        let q = 'INSERT INTO Figure (';
        let v = ' VALUES (';
        Object.keys(upd).forEach((key) => {
            if (params.length > 0) {
                q += ', ';
                v += ', ';
            }
            q += key;
            v += '?';
            params.push(upd[key]);
github microsoft / BotFramework-Emulator / packages / app / main / src / server / state / botEndpoint.ts View on Github external
fetchOptions.headers = {
          ...fetchOptions.headers,
          Authorization: `Bearer ${await this.getAccessToken(forceRefresh)}`,
        };
      } catch (e) {
        return {
          status: e.status,
          message: "The bot's Microsoft App ID or Microsoft App Password is incorrect.",
        };
      }
    }

    const response = await this._options.fetch(url, fetchOptions);

    if (
      (response.status === HttpStatus.UNAUTHORIZED || response.status === HttpStatus.FORBIDDEN) &&
      !forceRefresh &&
      this.msaAppId
    ) {
      return this.fetchWithAuth(url, fetchOptions, true);
    }

    return response;
  }
github Matterwiki / Matterwiki / src / api / utils / constants.js View on Github external
status: HttpStatus.UNAUTHORIZED,
    code: "INVALID_TOKEN",
    message: "Failed to authenticate token"
  },
  BAD_ARTICLE_CREATE: {
    status: HttpStatus.BAD_REQUEST,
    code: "BAD_ARTICLE_CREATE",
    message: "title, topicId and content are required"
  },
  BAD_ARTICLE_UPDATE: {
    status: HttpStatus.BAD_REQUEST,
    code: "BAD_ARTICLE_UPDATEE",
    message: "title, topicId, change_log and content are required"
  },
  NO_ACCESS: {
    status: HttpStatus.FORBIDDEN,
    code: "NO_ACCESS",
    message: "You are not authorized to perform this action"
  },
  NOT_FOUND: {
    status: HttpStatus.NOT_FOUND,
    code: "NOT_FOUND",
    message: "Resource was not found"
  },
  DELETE_DEFAULT_TOPIC: {
    status: HttpStatus.METHOD_NOT_ALLOWED,
    code: "DELETE_DEFAULT_TOPIC",
    message: "Can not delete default topic!"
  },
  DELETE_DEFAULT_ADMIN: {
    status: HttpStatus.METHOD_NOT_ALLOWED,
    code: "DELETE_DEFAULT_ADMIN",
github watscho / express-mongodb-rest-api-boilerplate / src / middleware / authMiddleware.js View on Github external
async isUnverfied (req, res, next) {
    const { context: { user: { account: { verification: { verified } } } } } = req

    if (verified) {
      return res.status(HttpStatus.FORBIDDEN)
        .json({ error: 'You have already verified.' })
    }

    return next()
  }
github stanislav-web / ecs-auth-microservice / app / src / api / access / controller.js View on Github external
await updateUser(dbuser._id || dbuser.email);
                    ctx.body = {
                        status: HttpStatus.OK,
                        message: {
                            expires_in: obj.expires_in,
                            token: obj.token
                        }
                    };
                } catch (err) {
                    throw new ApiAccessBoundleError(
                        HttpStatus.SERVICE_UNAVAILABLE, err.message
                    );
                }
            } else {
                throw new ApiAccessBoundleError(
                    HttpStatus.FORBIDDEN, 'Invalid credentials'
                );
            }
        } else {
            throw new ApiAccessBoundleError(
                HttpStatus.NOT_FOUND, 'User not found'
            );
        }
    } else {
        throw new ApiAccessBoundleError(
            HttpStatus.BAD_REQUEST, res.error.message
        );
    }

    await next();
};
github Prior99 / hyrest / packages / hyrest / src / answers.ts View on Github external
export function forbidden(arg1: T | string | Wrapper, arg2?: string): T {
    return answer(HTTP.FORBIDDEN, arg1, arg2);
}
github adobe / commerce-cif-common / src / web-action-transformer / exception-mapper-transformer.js View on Github external
*    governing permissions and limitations under the License.
 *
 ******************************************************************************/

'use strict';

const ITransformerPipelineAction = require('./transformer-pipeline').ITransformerPipelineAction;
const HttpStatusCodes = require('http-status-codes');
const ErrorResponse = require('@adobe/commerce-cif-model').ErrorResponse;

const ERROR_NAME_TO_STATUS_CODE = {
    'InvalidArgumentError': HttpStatusCodes.BAD_REQUEST,
    'MissingPropertyError': HttpStatusCodes.BAD_REQUEST,
    'CommerceServiceResourceNotFoundError': HttpStatusCodes.NOT_FOUND,
    'CommerceServiceBadRequestError': HttpStatusCodes.BAD_REQUEST,
    'CommerceServiceForbiddenError': HttpStatusCodes.FORBIDDEN,
    'CommerceServiceUnauthorizedError': HttpStatusCodes.UNAUTHORIZED,
    'NotImplementedError': HttpStatusCodes.NOT_IMPLEMENTED
};

/**
 * If the action ended with an error, this transformer maps the error to a status code and updates the response message.
 *
 * @extends ITransformerPipelineAction
 */
class ExceptionMapperTransformerPipelineAction extends ITransformerPipelineAction {
    transform(httpResponse, resultFromOwSequence) {
        if (!httpResponse.error) {
            return httpResponse;
        }

        let message;
github daGrevis / msks / backend / src / server / middlewares / withChannel.js View on Github external
ctx.status = HttpStatus.NOT_FOUND
    return
  }

  const connection = state.connections[channel.connectionId]

  if (!channel.isPublic) {
    if (!ctx.session) {
      ctx.body = { error: 'Session required!' }
      ctx.status = HttpStatus.UNAUTHORIZED
      return
    }

    if (connection.accountId !== ctx.session.accountId) {
      ctx.body = { error: 'Connection forbidden for session!' }
      ctx.status = HttpStatus.FORBIDDEN
      return
    }
  }

  ctx.channel = channel
  ctx.connection = connection
  return next()
}