digitalfabrik/integreat-app

View on GitHub
shared/api/errors/MappingError.ts

Summary

Maintainability
A
0 mins
Test Coverage
class MappingError extends Error {
  getMessage = (endpointName: string, message: string): string =>
    `MappingError: Failed to map the json for the ${endpointName} endpoint. ${message}`

  constructor(endpointName: string, message: string) {
    super()

    // captureStackTrace is not always defined on mobile
    // https://sentry.tuerantuer.org/organizations/digitalfabrik/issues/263/
    // https://sentry.tuerantuer.org/organizations/digitalfabrik/issues/265/
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition,@typescript-eslint/strict-boolean-expressions
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, MappingError)
    }

    this.message = this.getMessage(endpointName, message)
  }
}

export default MappingError