private getError()

in authui-container/server/utils/http-server-request-handler.ts [171:201]


  private getError(httpResponse: HttpResponse, defaultMessage: string): Error {
    let jsonResponse: ErrorResponse;
    let error: Error;
    try {
      jsonResponse = typeof httpResponse.body === 'object' ?
          httpResponse.body : JSON.parse(httpResponse.body);
      error = new Error(
          (jsonResponse &&
           jsonResponse.error &&
           jsonResponse.error.message &&
           jsonResponse.error.message.toString()) || defaultMessage);
    } catch (e) {
      // If the error response body is a string. Use the string as the error message.
      // This is the case for GCS:
      // response.body === 'No such object: gcip-iap-bucket-625969875839/config.json'
      // response.body === 'Not found'
      error = new Error(typeof httpResponse.body === 'string' ? httpResponse.body : defaultMessage);
    }
    if (jsonResponse &&
        jsonResponse.error &&
        jsonResponse.error.message &&
        jsonResponse.error.code) {
      addReadonlyGetter(error, 'cloudCompliant', true);
    } else {
      addReadonlyGetter(error, 'cloudCompliant', false);
    }
    addReadonlyGetter(error, 'rawResponse', httpResponse.body);
    // Append status code as it is more reliable than error messages.
    addReadonlyGetter(error, 'statusCode', httpResponse.statusCode);
    return error;
  }