HttpController.prototype.sendError = function(httpErrorCode, applicationErrorCode, errorName, errorDetails) { var request = require("http/v3/request"); var clientAcceptMediaTypes = this.normalizeMediaTypeHeaderValue(request.getHeader('Accept')) || ['application/json']; var isHtml = clientAcceptMediaTypes.some(function(acceptMediaType){ return this.isMimeTypeCompatible( '*/html', acceptMediaType); }.bind(this)); var response = require("http/v3/response"); response.setStatus(httpErrorCode || response.INTERNAL_SERVER_ERROR); if(isHtml){ var message = errorName + (applicationErrorCode!==undefined ? '['+applicationErrorCode+']' : '') + (errorDetails ? ': ' + errorDetails : ''); response.sendError(httpErrorCode || response.INTERNAL_SERVER_ERROR, message); } else { var body = { "code": applicationErrorCode, "error": errorName, "details": errorDetails }; response.setHeader("Content-Type", "application/json"); response.print(JSON.stringify(body, null, 2)); } this.closeResponse(); };
/* * Copyright (c) 2010-2019 SAP and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * SAP - initial API and implementation */ var request = require('http/v3/request'); request.getHeader('header1') === 'header1';