input: Write a function to design a web server in Python using the Flask framework that would serve a JSON object containing the current temperature for a city based on the city name given in the request. If the city name is not provided or the request is invalid, return an error message.
  
  from flask import Flask, request, jsonify
  import requests
  
  app = Flask(__name__)
  
  @app.route('/getTemp', methods=['POST'])
  def get_temp():
      if 'city' not in request.json:
          return jsonify({'error': 'City name not provided'}), 400
      
      city = request.json['city']
      url = 'http://api.openweathermap.org/data/2.5/weather?q={}&APPID=xxxxxx'
      try:
          r = requests.get(url.format(city))
          r.raise_for_status()
          weather = r.json()
          return jsonify({'temperature': weather['main']['temp']})
      except requests.exceptions.RequestException as e:
          return jsonify({'error': 'Failed to retrieve temperature data'}), 500
      except KeyError:
          return jsonify({'error': 'Invalid city name or weather data format'}), 400
  
  if __name__ == '__main__':
      app.run(debug=True)
  
  assert get_temp({'city': 'London'})=={'temperature': 280.32}
  assert get_temp({'city': ''})=={'error': 'Invalid city name or weather data format'}
  assert get_temp({})=={'error': 'City name not provided'}
  assert get_temp({'city': 'InvalidCityName'})=={'error': 'Invalid city name or weather data format'}
output: 
  def get_temp():
      if 'city' not in request.json:
          return jsonify({'error': 'City name not provided'}), 400
      
      city = request.json['city']
      url = 'http://api.openweathermap.org/data/2.5/weather?q={}&APPID=xxxxxx'
      try:
          r = requests.get(url.format(city))
          r.raise_for_status()
          weather = r.json()
          return jsonify({'temperature': weather['main']['temp']})
      except requests.exceptions.RequestException as e:
          return jsonify({'error': 'Failed to retrieve temperature data'}), 500
      except KeyError:
          return jsonify({'error': 'Invalid city name or weather data format'}), 400
  