How to use the italia-ts-commons/lib/responses.ResponseErrorInternal function in italia-ts-commons

To help you get started, we’ve selected a few italia-ts-commons 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 teamdigitale / io-functions / lib / utils / source_ip_check.ts View on Github external
return new Promise(resolve => {
      // extract the x-forwarded-for header and the allowed cidrs from the params
      const x = extractor(p1, p2, p3, p4, p5, p6);
      const maybeClientIp = x.e1;
      const cidrs = x.e2;

      if (isNone(maybeClientIp)) {
        return resolve(
          ResponseErrorInternal(
            "IP address cannot be extracted from the request"
          )
        );
      }

      if (
        // either allowed CIDRs is empty or client IP is contained in allowed CIDRs
        cidrs.size === 0 ||
        isContainedInCidrs(maybeClientIp.value, cidrs)
      ) {
        // forward request to handler
        return resolve(handler(p1, p2, p3, p4, p5, p6));
      } else {
        // respond with Not Authorized
        return resolve(ResponseErrorForbiddenNotAuthorized);
      }
github teamdigitale / io-functions / lib / utils / middlewares / azure_user_attributes.ts View on Github external
return left, IAzureUserAttributes>(
        ResponseErrorInternal(
          `Missing, empty or invalid ${HEADER_USER_EMAIL} header`
        )
      );
    }

    const userEmail = errorOrUserEmail.value;

    const errorOrUserSubscriptionId = NonEmptyString.decode(
      request.header(HEADER_USER_SUBSCRIPTION_KEY)
    );

    if (isLeft(errorOrUserSubscriptionId)) {
      return left, IAzureUserAttributes>(
        ResponseErrorInternal(
          `Missing or empty ${HEADER_USER_SUBSCRIPTION_KEY} header`
        )
      );
    }

    const subscriptionId = errorOrUserSubscriptionId.value;

    // serviceId equals subscriptionId
    const errorOrMaybeService = await serviceModel.findOneByServiceId(
      subscriptionId
    );

    if (isLeft(errorOrMaybeService)) {
      winston.error(
        `No service found for subscription|${subscriptionId}|${JSON.stringify(
          errorOrMaybeService.value
github teamdigitale / io-functions / lib / controllers / profiles.ts View on Github external
() =>
      // this should never happen since if the profile doesn't exist this function
      // will never be called, but let's deal with this anyway, you never know
      ResponseErrorInternal(
        "Error while updating the existing profile, the profile does not exist!"
      ),
    p => ResponseSuccessJson(toExtendedProfile(p))
github teamdigitale / io-functions / lib / utils / middlewares / context_middleware.ts View on Github external
() =>
          resolve(
            left>(
              ResponseErrorInternal("Cannot get context from request")
            )
          ),
        context => resolve(right>(context))
github teamdigitale / io-functions / lib / utils / request_middleware.ts View on Github external
e => {
        ResponseErrorInternal(e).apply(response);
        winston.log("debug", `wrapRequestHandler|ERROR|${request.url}|${e}`);
      }
    );
github teamdigitale / io-functions / lib / controllers / adm / services.ts View on Github external
...currentService,
          ...serviceFromPayload,
          serviceId
        };
      }
    );
    if (isLeft(errorOrMaybeUpdatedService)) {
      return ResponseErrorQuery(
        "Error while updating the existing service",
        errorOrMaybeUpdatedService.value
      );
    }

    const maybeUpdatedService = errorOrMaybeUpdatedService.value;
    if (isNone(maybeUpdatedService)) {
      return ResponseErrorInternal("Error while updating the existing service");
    }

    return ResponseSuccessJson(
      retrievedServiceToPublic(maybeUpdatedService.value)
    );
  };
}