Skip to content

Commit

Permalink
allow sending certain errors to the user
Browse files Browse the repository at this point in the history
this is useful because:

      // onedrive gives some errors here that the user might want to know about
      // e.g. these happen if you try to login to a users in an organization,
      // without an Office365 licence or OneDrive account setup completed
      // 400: Tenant does not have a SPO license
      // 403: You do not have access to create this personal site or you do not have a valid license
  • Loading branch information
mifi committed Sep 6, 2023
1 parent 9f160f4 commit a28fcec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const logger = require('../logger')
const { ProviderApiError, ProviderAuthError } = require('./error')
const { ProviderApiError, ProviderUserError, ProviderAuthError } = require('./error')

async function withProviderErrorHandling ({ fn, tag, providerName, isAuthError = () => false, getJsonErrorMessage }) {
async function withProviderErrorHandling ({
// eslint-disable-next-line no-unused-vars
fn, tag, providerName, isAuthError = () => false, isUserFacingError = (response) => false, getJsonErrorMessage,
}) {
function getErrorMessage (response) {
if (typeof response.body === 'object') {
const message = getJsonErrorMessage(response.body)
Expand All @@ -25,6 +28,7 @@ async function withProviderErrorHandling ({ fn, tag, providerName, isAuthError =
if (response) {
// @ts-ignore
if (isAuthError(response)) err2 = new ProviderAuthError()
if (isUserFacingError(response)) err2 = new ProviderUserError({ message: getErrorMessage(response) })
else err2 = new ProviderApiError(getErrorMessage(response), response.statusCode)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ export default class ProviderView extends View {
this.plugin.setPluginState({ folders, files, breadcrumbs, filterInput: '' })
})
} catch (err) {
// This is the first call that happens when the provider view loads, after auth, so it's probably nice to show any
// error occurring here to the user.
if (err instanceof UserFacingApiError) {
this.plugin.uppy.info({ message: this.plugin.uppy.i18n(err.message) }, 'warning', 5000)
return
}

this.handleError(err)
} finally {
this.setLoading(false)
Expand Down

0 comments on commit a28fcec

Please sign in to comment.