diff --git a/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php b/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php
index 64856816fb18ea2af8ea18c4aed4491663daf438..0d1dc310f62637e0010f940b1040fcdbc6ef5314 100644
--- a/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php
+++ b/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php
@@ -40,6 +40,10 @@ class SimpleSAML_Bindings_SAML20_HTTPRedirect {
 
 		$md = $this->metadata->getMetaData($remoteentityid, $metadataset);
 		$idpTargetUrl = $md[$endpoint];
+		
+		if (!isset($idpTargetUrl) or $idpTargetUrl == '') {
+			throw new Exception('Could not find endpoint [' .$endpoint  . '] in metadata for [' . $remoteentityid . '] (looking in ' . $metadataset . ')');
+		}
 	
 		$encodedRequest = urlencode( base64_encode( gzdeflate( $request ) ));