mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-11-04 10:06:32 +02:00 
			
		
		
		
	"invalid response" error: add isHafasError flag
So that consuming code can tell that this error is caused by an invalid/unexpected response from HAFAS.
This commit is contained in:
		
							parent
							
								
									33d77868a4
								
							
						
					
					
						commit
						e032ec1acd
					
				
					 1 changed files with 10 additions and 2 deletions
				
			
		
							
								
								
									
										12
									
								
								index.js
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								index.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -256,7 +256,11 @@ const createClient = (profile, userAgent, opt = {}) => {
 | 
			
		|||
		return profile.request({profile, opt}, userAgent, req)
 | 
			
		||||
		.then(({res, common}) => {
 | 
			
		||||
			if (!Array.isArray(res.outConL) || !res.outConL[0]) {
 | 
			
		||||
				throw new Error('invalid response')
 | 
			
		||||
				const err = new Error('invalid response')
 | 
			
		||||
				// technically this is not a HAFAS error
 | 
			
		||||
				// todo: find a different flag with decent DX
 | 
			
		||||
				err.isHafasError = true
 | 
			
		||||
				throw err
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			const ctx = {profile, opt, common, res}
 | 
			
		||||
| 
						 | 
				
			
			@ -303,7 +307,11 @@ const createClient = (profile, userAgent, opt = {}) => {
 | 
			
		|||
		.then(({res, common}) => {
 | 
			
		||||
			if (!res || !Array.isArray(res.locL) || !res.locL[0]) {
 | 
			
		||||
				// todo: proper stack trace?
 | 
			
		||||
				throw new Error('invalid response')
 | 
			
		||||
				const err = new Error('invalid response')
 | 
			
		||||
				// technically this is not a HAFAS error
 | 
			
		||||
				// todo: find a different flag with decent DX
 | 
			
		||||
				err.isHafasError = true
 | 
			
		||||
				throw err
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			const ctx = {profile, opt, res, common}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue